problem using page.registerstartupscript
I am using page.registerstartupscr开发者_如何学Goipt in my code behind C#. Its like this:
string item1="category1"; string Script = "window.program = '" + item1 + "';"; Page.RegisterStartupScript("PopupScript", Script);
item1 gets generated dynamically from some value in code behind. But its not working. Any suggestoins where I m getting wrong?
You need it wrapped in script tags, there's an overload for this in the newer replacement ClientScript
:
string item1="category1";
string Script = "window.program = '" + item1 + "';";
Page.ClientScript.RegisterStartupScript(GetType(), "PopupScript", Script, true);
Unless you're on .Net 1.1 I believe, Page.RegisterStartupScript
is deprecated.
精彩评论