Ajax Tips

I have created a Web user control and have a button, when I press on that button I register a script with Page.ClientScript.RegisterStartupScript and it works. But when I put the control into my UpdatePanel the client-side script will not work, any idea?

You need to use the ScriptManager to register the script block, because the scripts registered with the Page object will not be sent back to the client after a partial update. You can for example use the ScriptManager.GetCurrent method to get the instance of the ScriptManager added to your page, and then use its RegisterClientScriptBlock method, for example:


Dim current As ScriptManager = ScriptManager.GetCurrent(Me.Page)

current.RegisterClientScriptBlock(Me.Page, Me.GetType(), "key", "your script", True)


ScriptManager current = ScriptManager.GetCurrent(this.Page);

current.RegisterClientScriptBlock(this.Page, this.GetType(), "key2, "your script", true);


Post a Comment


Close Menu