Hello All,

I have a web application with master page.
master page has accordian (vertical) menu with favorites section where user can drag menu items dynamically.
user has to press 'save' button to save these newly dragged items.
My problem is after pressing 'save' button, these control's do not render until I press F5.
Is there any way that I could refresh the master page content and render the new controls when 'save' button is clicked.

I have tried:

page_load(this,null)

It doesn't help.

Please help.

Thank you.

Regards
hitro

Dani AI

Generated

You do not need to refresh the whole page. The master just needs to rebind its data after the save. is right that you must get a postback, but a normal Button already posts back; the real issue is that your favorites menu in the master is not being rebound on that same request.

A simple, robust pattern is to expose a method on the master that reloads the favorites, then call it from the content page right after you persist changes.

// Site.Master.cs
public partial class SiteMaster : MasterPage
{
    public void ReloadFavorites()
    {
        var items = FavoriteRepo.GetForUser(User.Identity.Name);
        AccordionMenu.DataSource = items;   // e.g., Repeater/Menu/TreeView
        AccordionMenu.DataBind();
    }
}
// SomePage.aspx.cs (the page with the Save button)
protected void Save_Click(object sender, EventArgs e)
{
    FavoriteRepo.Save(User.Identity.Name, draggedItemIds);
    var m = Master as SiteMaster;
    if (m != null) m.ReloadFavorites();     // refresh master immediately
}

If you create the accordion items dynamically (not via a databound control), recreate them on every request with stable IDs so ViewState works on the next round trip. Build them as early as possible, typically in OnInit.

// Site.Master.cs
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    BuildFavorites(); // rebuild control tree with consistent IDs each request
}

Using ASP.NET AJAX? Wrap the master’s menu in an UpdatePanel and add the Save button as an AsyncPostBackTrigger, or call UpdatePanelMenu.Update() after ReloadFavorites(). ’s redirect suggestion also works (classic PRG pattern), but it is heavier and resets scroll/state, so try the direct rebind first.

Recommended Answers

All 2 Replies

possibly set the button's autopostback = true.

try

Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.