Saturday, March 24, 2012

UpdatePanel and Dynamic Controls...

Hello all,

I have created a *.ascx (UserControl) which I added in the web form in UpdatePanel dynamically using Page.LoadControl function. The control is rendered fine. But the client side event handlers (that I defined in the javascript of the UserControl) are not rendered. When that event is raised, it raises the "Object Required" javascript exception. It happens because that function (handler) is not rendered. Please give me solution to this problem. Here is the sample

(this is done on server side Page_Load event handler)

WebCombo1.ClientSideEvents.BeforeDropDown =

"WebCombo_BeforeDropDown" + ControlID;

(Now I have defined the handler on the client side as)

function WebCombo_BeforeDropDown<%=ControlID%>(webComboId)

{

.... my code here...

}

Thanks in Advance

Mudassar

The reason it does not work is because innerHTML, which UpdatePanel framework uses on the client side, does not work for embedded script tags in HTML.

If you can register the script blocks using ScriptManager.RegisterClientScriptBlock that will be the best. So instaed of putting them in script Tags generate them in a string and use ScriptManager.RegisterClientScriptBlock.

No comments:

Post a Comment