Tutorial :Update a User Control from another User Control via AJAX



Question:

Maybe I'm having a brain fart or something because it seems like this should be pretty simple but how do you update a User Control from another User Control via Ajax?

I have an ASPX page with two user controls and when I trigger a server-side event on one, I want to refresh a grid on the other so it'll update it's data.

I'm using Telerik controls if that helps. Checkbox event on the first User Control causes the RadGrid in the second User Control to Rebind() and I have RadAjaxManager in the ASPX page and RadAjaxManagerProxy in the two User Controls.


Solution:1

First for me Page.DataBind() doesn't work for me.

I declared in UserControl

// Declare a delegate  public delegate void save_CommandEventHandler ();    //Event  save_CommandEventHandler SaveViewChanged public event;    // I run SaveViewChanged() from a click_button but it can run from anywhere  protected void save_Click (object sender, EventArgs e)  {      UpdateDataInDatabase();        SaveViewChanged ();  }  

In page.aspx.cs code

protected override void OnInit (EventArgs e)  {      base.OnInit (e);        // UserControle1 is the Id of your UserControl declared in Aspx Page      UserControle1.SaveViewChanged + =         New UserControle.save_CommandEventHandler         (Save_CommandEventHandler);  }    private void save_CommandEventHandler () {      // Reload the gridView gvExpence to see the change operated in the user control      gvExpence.DataSource =DataAcces.getAllCompanyExpence ();      gvExpence.DataBind ();        // update user control 2      usercontrol2.updateView();  }  


Solution:2

An async callback will update the control that caused the postback and also any parent controls of its update panel. If your datagrid is not being updated in the browser after an event it would suggest its update method is not being called

Try calling the .update method of the datagrids updatepanel in the checkbox event


Solution:3

You could try using the ajaxRequest or ajaxRequestWithTarget client-side methods of the AjaxManager to initiate an ajax call. More info about these methods can be found on the Telerik's online documentation: http://www.telerik.com/help/aspnet-ajax/ajxclientsideapi.html


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