0

I am working on a custom control that is being used on a webpage that contains many updatepanels. In my custom control, there is extensive use of jquery and many plugins are used as well. Now, on every updatepanel's postback, THE CONTROL GETS RENDERED AGAIN AND AGAIN, it loads the javascript resources again too, but doesnt call the javascript functions again. This is causing problem that many elements in my control which has to be turned in to one thing or another by jquery plugin are not working(javascript functions not calling in simple).

Now I have tried many solutions, including the ones mentioned in this question How to have a javascript callback executed after an update panel postback? but in vain. Previously, when my page contained only one updatepanel,

pageLoad(sender, Args);

functon was working fine, now in the case of multiple updatepanels that is not working, neither

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);

function pageLoaded() { }
Community
  • 1
  • 1
Taha Rehman Siddiqui
  • 2,441
  • 5
  • 32
  • 58

1 Answers1

1

If you don't want your control to refresh on every UpdatePanel's postback - set UpdateMode for the UpdatePanel that hosts your control to Conditional this way it will be refreshed only when its own trigger or child control fire (Ref: http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.updatemode(v=vs.90).aspx).

That said, you don't have to manually add pageLoaded event handler on client side. Use intristic pageLoad function which fires on every page load be it via UpdatePanel or otherwise (Ref: http://msdn.microsoft.com/en-us/library/bb386417(v=vs.90).aspx)

One other way to fire a JS function is from server-side code. Every time your control loads or performs some server-side init - use ClientScript.RegisterStartupscript call to make sure JS function will be called on the client afterward, for example

ClientScript.RegisterStartupscript(this.GetType(),"myFunc", "myFunction();", true);

Ref: http://msdn.microsoft.com/en-us/library/z9h4dk8y(v=vs.90).aspx

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136