简体   繁体   English

仅从内容页面刷新母版页

[英]Refresh the master page only from the content page

I don't know how to refresh my Master Page (only) from a button click located in the ContentPlaceHolder part. 我不知道如何通过ContentPlaceHolder部分中的按钮单击刷新我的母版页(仅)。

Here is an image explaining the situation (I blurred the useless part). 这是一张说明情况的图片(我模糊了无用的部分)。

Things to know: 要知道的事情:

Blue : MasterPage 蓝色:MasterPage

Green : Part of the MasterPage I want to refresh 绿色:我要刷新的母版页的一部分

Red : ContentPlaceHolder (another aspx page) of the MasterPage 红色:MasterPage的ContentPlaceHolder(另一个aspx页面)

I want to refresh the green part of the MasterPage with the Click event of the Button on the red part. 我想用红色部分上的Button的Click事件刷新母版页的绿色部分。

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. 我尝试了围绕绿色部分的更新面板,触发器是红色部分按钮的Click事件,但是由于它与aspx页面不同,因此失败。

any ideas ? 有任何想法吗 ?

ProblemRefresh

EDIT: My code 编辑:我的代码

Master page C# part: 母版页C#部分:

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

Master page Asp part: 母版页Asp部分:

 <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: ContentPlaceHolder C#部分:

//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). 我使用调试器进行跟踪,编译过程通过UpdateComment方法进行,但是Updatepanel没有刷新(或者至少是isnt标签)。 When i refresh the full page (F5), the label is refreshed with the new comment 当我刷新整页(F5)时,标签会用新注释刷新

Any ideas ? 有任何想法吗 ?

Try to use (Its predocode, since you didn't specify language) 尝试使用(它的predocode,因为您没有指定语言)

In ContentPlaceHolder server language script (eg .vb, .cs files) 在ContentPlaceHolder服务器语言脚本中(例如.vb,.cs文件)

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 在MasterPage中

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

Make the master's UpdatePanel 's UpdateMode=Conditional and update it manually from the page. 使母版的UpdatePanelUpdateMode=Conditional并从页面手动对其进行更新。 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 : 此方法接受您要更改的信息,并调用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 . 您必须将页面的Master属性转换为正确的类型才能查看UpdateComment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM