This is a migrated thread and some comments may be shown as answers.

Update control in master page after database changes.

1 Answer 155 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 24 Aug 2018, 07:45 PM

     Hi,

 

Using this ajaxify exampleI need execute code in codebehind, and then update the master page control

https://docs.telerik.com/devtools/aspnet-ajax/controls/ajaxmanager/how-to/ajaxify-and-update-controls-in-master-and-content-page

Something like this:

Content Page

protected void Page_Load(object sender, EventArgs e)
{
    RadAjaxManager AjaxManager = RadAjaxManager.GetCurrent(Page);
    RadMenu RadMenu1 = (RadMenu)this.Master.FindControl("RadMenu1");
    AjaxManager.AjaxSettings.AddAjaxSetting(btnSaveChanges, RadMenu1);
}
 
protected void btnIncrease_Click(object sender, EventArgs e)
{
     ...
     context.SaveChanges();

     // And then, Update Radmenu in MasterPage  
 

}

In my scenario, RadMenu have a CSS indicador of numbers of items in database updated in Page_Load().  But, when I click in btnSaveChanges  in Content Page, always RadMenu update before database is changed.

 

Any way to reverse this?

 

Thank you!

 

 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 26 Aug 2018, 05:55 PM
Hello Manuel,

The Page_Load event fires before postback events such as OnClick of a button, so you would need to make sure that the code you want to run after the database update runs (again) in the OnClick event. Perhaps you can extract it into a method so you can call it when necessary. You can read more on the page lifecycle in the following MSDN article: https://msdn.microsoft.com/en-us/library/ms178472.aspx. I also advise that you first make sure that the desired functionality works without AJAX, as partial rendering can sometimes hide errors and make the code harder to debug. Then, after adding AJAX, make sure that you have all relevant content updated from the server. For example, if the indicator is added to an element outside of the RadMenu, with the provided settings it will not travel to the browser and will not seem to be updated even if it is changed on the server.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Ajax
Asked by
Manuel
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or