It took me almost two hours to solve this problem.
Let's take a look at the parameter signature of RegisterStartupScript:
RegisterStartupScript (control, type, key, script, addScriptTags)
RegisterStartupScript (page, type, key, script, addScriptTags)
In my personal impression, this is the same as the current Page object, but it is indeed different.
Look at the two overload functions above,
When we use the first method, the added code is not executed in any case.
But when using the second method, there is no problem.
Explanations for foreign cool people:
---
I cocould resolve this issue and just thought of updating here if anyone else face it sometime. the problem is this. if you use ScriptManager. registerStartupScript and none of the update panels get updated at client due to UpdateMode = "Conditional" and ChildrenAsTriggers = "False", this method wont render script any. and this is weird because as per the ajax documentation, RegisterStartupScript Method (page, type, key, script, addScriptTags) will causes the script to be encoded each time an asynchronous postback occurs.
If you didn't notice it already, RegisterStartupScript method has two overloaded instances. one takes Control and other Page as the first arguments (rest of the arguments are common ). and if you use the one which takes page as argument, its suppose to render the script everytime which id doesn't. this is apparently a bug in asp.net ajax.
I reflected these methods using Lutz Roeder's. net Reflector (amazing tool by the way if you haven't used already) and found that both of these methods call ScriptRegistrationManager. registerStartupScript (control, type, key, script, addScriptTags ). I don't understand how calling a same method with same code from two different methods makes any difference. so it seems that RegisterStartupScript Method (page, type, key, script, addScriptTags) method is duplicate and just useless.
Anand
---
This was a bug in asp.net ajax.
This demo doesn' t work:
scripts = "alert(123);";
ScriptManager.RegisterStartupScript(this, this.GetType(), "showWindow", scripts, true);
This demo is working:
scripts = "alert(123);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showWindow", scripts, true);
Over.