1

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 ?

charles godin
  • 63
  • 2
  • 6
  • 1
    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 Jun 12 '15 at 12:03
  • This might be useful... http://stackoverflow.com/questions/6035730/asp-net-how-to-call-a-master-page-event-handler-from-content-page-event-handle – Turnip Jun 12 '15 at 12:03

2 Answers2

0

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
}
Gift Rise
  • 3
  • 4
  • Hello, i updated my question and put some codes, if you could take a look at it please :), thanks for your idea – charles godin Jun 12 '15 at 12:28
  • `this.UPDP_Obs.Update();` No, is this how that label is refreshed, if it needs to fetch from DB, you need to do so using `//Some Code to Also Select from the database`. Add how that `this.UPDP_Obs` originally collects its info from the DB, that same way should be in the place where `this.UPDP_Obs.Update();` is currently – Gift Rise Jun 12 '15 at 12:34
0

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.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Hello, i just tried your solution and it doesn't works, I think the idea is good and I may use it wrong, i've update my Thread question with code, can you take a look ? – charles godin Jun 12 '15 at 12:28
  • @charlesgodin: i don't see where you change the comment in your code. – Tim Schmelter Jun 12 '15 at 12:30
  • @charlesgodin: i've seen that but i don't see where you change the comment. If nothing was change what do you expect to be updated? – Tim Schmelter Jun 12 '15 at 12:43