Tutorial :how can I reload an update panel onclient side using javascript?



Question:

I have a gridview button that I programmatically created and I want to load an update panel on the client side with the sent data. I have a hidden value field that gets its data on the click of the gridview button and the dropdownlist in my updatepanel depends on that value.


Solution:1

while calling __doPostBack directly will work, it's not a perfect solution because the name of that function is strictly speaking an implementation detail of the .Net framework.

A better solution is to use ClientScriptManager.GetPostBackEventReference, which gives you a more resilient interface to the same functionality. Do note that GetPostBackEventReference and GetCallBackEventReference are not the same thing - the former causes a page reload (partial or full, depending on how your UpdatePanels are set up), while the latter doesn't.


Solution:2

The easiest way to do this is to call __doPostBack from client side.

On client side button1_onclick method, calls:

__doPostBack('<%=UpdatePanel1.ClientID %>','Refresh:0,1,2');    //refresh update panel  

On page behind add the following event handler to capture the post back call:

protected void UpdatePanel1_Load(object sender, EventArgs e)  {      string arg = Request.Form["__EVENTARGUMENT"];        if (string.IsNullOrEmpty(arg)) return;        if (arg.StartWith("Refresh")      {           //parse data first then do your thing here...      }  }  

And of course don't forget to wire event to the above method:

protected void Page_Init(object sender, EventArgs e)  {                 UpdatePanel1.Load += new EventHandler(UpdatePanel1_Load);  }  


Solution:3

we use the __dopostback() method which simulates a postback and causes the updatepanel to refresh

__doPostBack('controlName','');  

Don't forget that the control name is it's HTML ID (which may well contain dollars etc) and not just it's ASP.NET ID.

As far as I know you can either call this method and pass in the hidden value field, or the div that it is in.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »