本文介绍了如何访问内容页母版页控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含了状态信息标签的母版页。我需要设置不同.aspx页的状态文本。这怎么可能从内容页做了什么?
公共部分类网站:System.Web.UI.MasterPage
{
公共字符串StatusNachricht
{
得到
{
返回lblStatus.Text;
}
组
{
lblStatus.Text =价值;
}
} 保护无效的Page_Load(对象发件人,EventArgs的发送)
{ }
}
我已经试过这一点,但在使其工作不成功的:
公共部分类DatenAendern:System.Web.UI.Page
{
VAR主=主为网站; 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(主!= NULL)
{
master.setStatusLabel();
}
} 保护无效grdBenutzer_RowCommand(对象发件人,GridViewCommandEventArgs E)
{
尝试
{
//一些code 如果(主!= NULL)
{
master.setStatusLabel(Passwort erfolgreich修订于。);
}
}
赶上(异常前)
{
如果(主!= NULL)
{
master.setStatusLabel(Passwort konnte nicht修订于werden!);
}
}
}
}
}
解决方案
在MasterPage.cs文件添加标签的
是这样的:属性
公共字符串的ErrorMessage
{
得到
{
返回lblMessage.Text;
}
组
{
lblMessage.Text =价值;
}
}
在你的 ASPX
页,略低于Page指令补充一点:
<%@页标题=LANGUAGE =C#的MasterPageFile =主路径名.....%GT;
<%@ VirtualPath的MasterType =主路径名%> //添加此
而在你的 codebehind(aspx.cs)
页面,您可以然后轻松地访问标签属性
并根据需要设置其文本
。像这样的:
this.Master.ErrorMessage =这里您的错误信息;
I have a master page which contains a label for status messages. I need to set the status text from different .aspx pages. How can this be done from the content page?
public partial class Site : System.Web.UI.MasterPage
{
public string StatusNachricht
{
get
{
return lblStatus.Text;
}
set
{
lblStatus.Text = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
I have tried this, but was unsuccessful in making it work:
public partial class DatenAendern : System.Web.UI.Page
{
var master = Master as Site;
protected void Page_Load(object sender, EventArgs e)
{
if (master != null)
{
master.setStatusLabel("");
}
}
protected void grdBenutzer_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
//some code
if (master != null)
{
master.setStatusLabel("Passwort erfolgreich geändert.");
}
}
catch (Exception ex)
{
if (master != null)
{
master.setStatusLabel("Passwort konnte nicht geändert werden!");
}
}
}
}
}
解决方案
In the MasterPage.cs file add the property
of Label
like this:
public string ErrorMessage
{
get
{
return lblMessage.Text;
}
set
{
lblMessage.Text = value;
}
}
On your aspx
page, just below the Page Directive add this:
<%@ Page Title="" Language="C#" MasterPageFile="Master Path Name"..... %>
<%@ MasterType VirtualPath="Master Path Name" %> // Add this
And in your codebehind(aspx.cs)
page you can then easily access the Label Property
and set its text
as required. Like this:
this.Master.ErrorMessage = "Your Error Message here";
这篇关于如何访问内容页母版页控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!