问题
can i change html client tags text , on the server side?
like for example, change h2 or p tags text on server side?
for example:
<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&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
change the h2 text from "Welcome to ASP.NET!" to "Hello".
回答1:
First add an ID and runat="server"
to the element:
<h2 id="myHeader" runat="server">
Then in the Page_Load
method:
myHeader.InnerHtml = "Hello";
回答2:
What you are probably looking for is the LiteralControl
provided by ASP.NET.
See: http://msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol.aspx
来源:https://stackoverflow.com/questions/5368331/change-html-tags-text-on-server-side-c-asp-net