1
votes

I don't know how to refresh my Master Page (only) from a button click located in the ContentPlaceHolder part.

Here is an image explaining the situation (I blurred the useless part).

Things to know:

Blue : MasterPage

Green : Part of the MasterPage I want to refresh

Red : ContentPlaceHolder (another aspx page) of the MasterPage

I want to refresh the green part of the MasterPage with the Click event of the Button on the red part.

I tried an update Panel surrounding the green part and the trigger is the Click event of the Red part button but since it's not the same aspx page, it fails.

any ideas ?

ProblemRefresh

EDIT: My code

Master page C# part:

public void UpdateComment()
        {
            this.UPDP_Obs.Update();
        }

Master page Asp part:

 <asp:UpdatePanel ID="UPDP_Obs" runat="server"
                             UpdateMode="Conditional">
                <ContentTemplate>

                <asp:Table CssClass="center" ID="TBL_ObsLA" runat="server">
                <asp:TableRow runat="server">
                    <asp:TableCell>
                        Dernier commentaire Ligne Cal-1 A:
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow runat="server"> 
                    <asp:TableCell>
                    <asp:Label ID="LBL_DateLA" runat="server" Text=""></asp:Label> <br /> <br />
                    <asp:Label ID="LBL_ObsLA" runat="server" Text=""></asp:Label>
                    </asp:TableCell>
                </asp:TableRow>

            </ContentTemplate>
</asp:UpdatePanel>

ContentPlaceHolder c# part:

//Some Code to Update the comment in Sql to a Database (works)


MasterLavage MasterP = (MasterLavage)this.Master;
MasterP.UpdateComment();

I traced with the debugger, the compilation go through the UpdateComment method but the Updatepanel isnt refreshed (or at least the label isnt). When i refresh the full page (F5), the label is refreshed with the new comment

Any ideas ?

2
I know this is probably the last thing you want to hear, but I would break away from the strict WebForms model and use JavaScript to do an Ajax request to pull in the data and then update the fields in JavaScript. UpdatePanels are so 2008. ;-) - BJ Safdie

2 Answers

0
votes

Try to use (Its predocode, since you didn't specify language)

In ContentPlaceHolder server language script (eg .vb, .cs files)

this.parent.method_that_updates(); //you can check if method exists before invoking, just to be safe; or wrap this in a try catch block

In MasterPage

public function method_that_updates() {
     this.my_panel.refresh(); //or whatever does the refresh
     //notice I made it public
}
0
votes

Make the master's UpdatePanel's UpdateMode=Conditional and update it manually from the page. You can provide a public method in your master that you can call from your page. This method accepts the informations that you want to change and calls Update:

// in your Masterpage
public void UpdateComment(string comment)
{
   this.LblComment.Text = comment;    // as label in the green part of the master
   this.CommentUpdatePanel.Update();  // the UpdatePanel around this control
}

You have to cast the page's Master property to the correct type to see UpdateComment.