Search

Jul 24, 2008

User Control and Javascript in UpdatePanel

Hi All,

There is general practices where we require some javascript function while useing UpdatePanel; along with the User Control; and the more problamatic is when the User Contorl is dynamic.

Problem:
When we use UserControl which change the state of Ajax postback; sometimes we require some javascript which needs to be embaded after loading the UserControl and with this said I am using UpdatePanel. Means my code is in the UpdatePanel.

Solution:
Generally we are using following code to run any javascript in code behind

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "alert('hi');", true);

Now if you are using UpdatePanel then replace you above code with following code.

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "key", "alert('hi');", true);

Now you can see the alert saying 'hi' to you!!

1 comment:

Sergio said...

Thanks very much, your post was very useful.

Best regards...
Sergio from Argentina