Wednesday, August 7, 2013

Using Jquery and JQuery UI inside AJAX UpdatePanel

I wanted to call a JQuery "alert" on the Click event of a button, which was also a Trigger to an Update Panel. My condition for the alert was in code behind. For those who experienced this, JQuery/javascript doesn't work nicely with UpdatePanel

Searching on Google led me to the solution below and it works as expected!

protected void btnPrevious_Click(object sender, ImageClickEventArgs e)
     int curpageindex=-1;
     if ((int)ViewState["Pageindex"] > 0)
     { 
         //Your code
         BindData();
     }
     else if ((int)ViewState["Pageindex"] == 0) 
         ScriptManager.RegisterStartupScript([updatePanelId], this.GetType(), "click", "firstrecord();", true);                       }
 
Please bear in mind that ScriptManager is the Ajax ScriptManager that has different overloading Parameters, one of them being a reference to the UpdatePanel.

Here's a nice explaination of how this works.

No comments: