SCENARIO
The BasePage.cs implements System.Web.UI.Page. It is a superclass without aspx from where all actual pages are derived.
I am registering some javascript in the BasePage using RegisterClientScriptBlock:
public class BasePage : System.Web.UI.Page
{
protected virtual void Page_Load(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
Type csType = this.GetType();
cs.RegisterClientScriptBlock(csType, "handler", @"<script language='javascript' type='text/javascript'>alert('Something stupid!');</script>");
}
}
I tested this snippet in a mock: it works right. Then I inserted the snippet in the BasePage.cs. In the index.aspx the script is not executed. Browser debugging shows that:
- no script has been registered
- no console error is displayed
In all other pages it works right.
QUESTION
Is there any specific issue related to the RegisterClientScriptBlock() method?
REMARK
I am sorry, but I am not allowed to post the whole index.aspx page code. But maybe if you have a clue then I can give you further details.
BasePageis this code? Does the codebehind ofindex.aspxinheritBasePageorPage? Does the codebehind ofindex.aspxoverride the method which callsRegisterClientScriptBlockand not call thebaseversion?virtualout of yourPage_Loaddefinition(s) - I think that might be your problem.