ASP.Net AJAX introduces the ScriptManager, and the ScriptManager introduces a set of API that look just like a set exposed by the ClientScriptManager in "traditional" ASP.Net; things like RegisterStartupScript, RegisterClientScriptInclude, etc.
The question is: why?
The answer is actually pretty elementary, but in really understanding it you kind of come to another understanding of ASP.net AJAX; well, actually, AJAX in general.
The way the ClientScriptManager (Me.Page.ClientScript or this.Page.ClientScript) works in "traditional" ASP.Net it maintains a list of all scripts on the Page, and when asked to render by the Page object, it properly works those scripts into the page output. The thing is, in ASP.Net AJAX, the page lifecycle is hijacked by the ScriptManager during partial rendering and therefore the Page is never asked to render; the ScriptManager takes care of choosing what controls to render, etc.
So code like this:
protected void Button1_Click (object sender, EventArgs e){
this.LinkButton1.Visible=true;
Page.ClientScript.RegisterStartupScript(this.GetType(), "linkonclick", "<script>document.getElementById('"+this.LinkButton1.ClientID+"')"+".onclick = function(){('click',alert('hello world'),true);}</script>");
}
}
.....will NOT work if Button1 is inside of an UpdatePanel - the ClientScriptManager is never asked to render its scripts; you're basically adding scripts to it for no good reason. This code DOES work, however, if Button1 is not within an UpdatePanel.
To make the above code work in an UpdatePanel you do the following....
protected void Button1_Click (object sender, EventArgs e){
this.LinkButton1.Visible=true;
ScriptManager.RegisterStartupScript(this, this.GetType(), "linkonclick", "<script>document.getElementById('"+this.LinkButton1.ClientID+"')"+".onclick = function(){('click',alert('hello world'),true);}</script>", false);
}
Nothing really changed except that we're now calling through the ScriptManager's static version of the RegisterStartupScript method. Since the script is registered with the ScriptManager, it is sent down to the client in the partial page refresh response as something the client script needs to introduce into the page DOM. Everything works now.