簡體   English   中英

如何從h1元素獲取文本?

[英]How to get the text from h1 element?

我有一個母版頁和內容頁:

1)在母版頁上:

標記:

<h1 id="SeoActionH1" runat="server"></h1>

后面的代碼:

public string SeoActionHeader1
{
    set
    {
        SeoActionH1.InnerText = string.IsNullOrEmpty(value) ? string.Empty : value;
    }
    get
    {
        return SeoActionH1.InnerText;
    }
}

2)在內容頁面上:

后面的代碼:

private Main MainMasterPage
{
    get { return Master as Main; }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        string groupName = MainMasterPage.SeoActionHeader1;
    }
}

例如,如果h1的內容是:您好,我得到以下信息:

"\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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM