Asp.net 如何从h1元素获取文本?
我有一个母版和内容页: 1) 在母版页上: 标记:Asp.net 如何从h1元素获取文本?,asp.net,Asp.net,我有一个母版和内容页: 1) 在母版页上: 标记: <h1 id="SeoActionH1" runat="server"></h1> 2) 在内容页上: 代码隐藏: public string SeoActionHeader1 { set { SeoActionH1.InnerText = string.IsNullOrEmpty(value) ? string.Empty : value; } get {
<h1 id="SeoActionH1" runat="server"></h1>
2) 在内容页上:
代码隐藏:
public string SeoActionHeader1
{
set
{
SeoActionH1.InnerText = string.IsNullOrEmpty(value) ? string.Empty : value;
}
get
{
return SeoActionH1.InnerText;
}
}
private Main MainMasterPage
{
get { return Master as Main; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string groupName = MainMasterPage.SeoActionHeader1;
}
}
例如,如果h1的内容是:Hello,我得到了以下信息:
"\r\n "
发生了什么事?您是否在页面加载事件中调用了此
SeoActionHeader1
属性
还是这样
public string MyString{ get; set; }
public void Page_Load(object sender, EventArgs e)
{
MyString = string.IsNullOrEmpty(value) ? string.Empty : value;
}
然后在标记中:
<h1><%= MyString %></h1>
您在h1
中的哪些位置设置值?它是先前从数据库中设置的。请将该代码放到问题中。设置值的位置。