change html tags text , on server side (C#, ASP.NET)

时间秒杀一切 提交于 2019-12-22 11:28:52

问题


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&amp;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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!