我不知道如何(仅)通过单击 ContentPlaceHolder 部分中的按钮来刷新我的母版页。
这是一张解释情况的图片(我模糊了无用的部分)。
要知道的事情:
蓝色:母版页
绿色:我想要刷新的 MasterPage 的一部分
红色:MasterPage 的 ContentPlaceHolder(另一个 aspx 页面)
我想用红色部分按钮的 Click 事件刷新 MasterPage 的绿色部分。
我尝试了围绕绿色部分的更新面板,触发器是红色部分按钮的 Click 事件,但由于它不是同一个 aspx 页面,因此失败。
有什么想法吗?
编辑:我的代码
母版页C#部分:
public void UpdateComment()
{
this.UPDP_Obs.Update();
}
母版页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# 部分:
//Some Code to Update the comment in Sql to a Database (works)
MasterLavage MasterP = (MasterLavage)this.Master;
MasterP.UpdateComment();
我用调试器跟踪,编译通过 UpdateComment 方法,但 Updatepanel 没有刷新(或者至少标签没有刷新)。 当我刷新整个页面(F5)时,标签将刷新并显示新评论
有什么想法吗?
最佳答案
尝试使用(它的预做代码,因为您没有指定语言)
在 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
在母版页中
public function method_that_updates() {
this.my_panel.refresh(); //or whatever does the refresh
//notice I made it public
}
关于javascript - 仅从内容页刷新母版页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802458/