Search This Blog

Sunday, April 3, 2011

Click event stopped firing after ajax postback

I had a user control on a SharePoint master page for one our client portal which was taking longer to load than other modules on the pages. 

Deciding to load this control asynchronously to speed up the page load I achieved this by adding button control inside the Ajax update panel. This button remains hidden from users view. I made the button click event to fire using JavaScript function by pushing it to body onload event using SharePoint's _spBodyOnLoadFunctionNames function.

The control worked as expected, causing the button click event to fire and processing the server side logic. However, the other buttons, link buttons and other server on other modules lost their events. Now nothing happens whenever I click on any server side button controls.

We tried various different options like calling the JavaScript function right into the script tag, mentioning it on the master page’s body onload event etc,. The final one which worked was ScriptManager's registerstartupscript function i.e. ScriptManager.RegisterStartupScript on the server side page load event. I registered the JavaScript function call using the RegisterStartupScript function provided by ScriptManager object. Now the page worked perfectly without any issue. Buttons, hyperlink buttons all worked smoothly.

I am still not sure what caused events to break by calling the function right into the page load. Your suggestions and advice are welcome.