2011-03-20 104 views
1

我可以在服務器端更改html客戶端標籤文本嗎?在服務器端更改html標籤文本(C#,ASP.NET)

像例如,在服務器端更改h2或p標籤文本?

例如: 「歡迎到ASP.NET」

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
<h2> 
    Welcome to ASP.NET! 
</h2> 
<p> 
    To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. 
</p> 
<p> 
    You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409" 
     title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. 
</p> 

變化從H2文本到「你好」。

回答

10

首先添加ID和runat="server"到元件:

<h2 id="myHeader" runat="server"> 

然後在Page_Load方法:

myHeader.InnerHtml = "Hello";