GKR
GKR

Reputation: 9

How do I Update GridView on Masterpage from button on ContentPage?

I have a MasterPage with a GridView on a UpdatePanel. On one of my content pages I have a button which adds items to a session which I want to appear in the Gridview which is on the MasterPage. I'v got the items in the Gridview but have problem with refresh or postback or something like that. Does anyone have an answere to this?

Upvotes: 0

Views: 1082

Answers (2)

jekcom
jekcom

Reputation: 2095

If you have refresh issue in updatepanel, then it means that the post back button is aether not inside the update panel or the panel is not updated manually.

For this case I assume you cant put the button inside the panel as it is part of content page, so i suggest you set panel's UpdateMode to conditional and have some refresh method on your masterpage. In order to see this method in the content page make some Interface with this method and let the masterpage use this interface.

then in the content page take the masterpage referense and consume the refresh method.

e.g.

The interface

public interface IMaster
{
    void RefreshPanel();
}

The masterpage

(note it uses the IMaster interface that we created before)

public partial class MasterPage : System.Web.UI.MasterPage,  IMaster
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Load items from session
    }

    public void RefreshPanel()
    {
        UpdatePanel1.Update();
    }
}

The content page

public partial class ContentPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

       //Add items to session 
       //....

        //Now refresh the updatepanel on the masterpage
        IMaster masterPage = Master as IMaster;
        masterPage.RefreshPanel();
    }
}

Upvotes: 1

Tim B James
Tim B James

Reputation: 20364

You will need to look into using Events and Delegates. Basically, you will create an Event on the Usercontrol which your MasterPage will react to. There are many other websites with examples, so just google ASP.NET Events and Delegates.

Upvotes: 0

Related Questions