更改 html 标签文本,在服务器端(C#、ASP.NET)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5368331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:28:09  来源:igfitidea点击:

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

htmltagsserver-side

提问by Rodniko

can i change html client tags text , on the server side?

我可以在服务器端更改 html 客户端标签文本吗?

like for example, change h2 or p tags text on server side?

例如,在服务器端更改 h2 或 p 标签文本?

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

将 h2 文本从“Welcome to ASP.NET!”更改为“Welcome to ASP.NET!” 到“你好”。

回答by Shadow Wizard is Ear For You

First add an ID and runat="server"to the element:

首先runat="server"向元素添加一个 ID 和:

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

Then in the Page_Loadmethod:

然后在Page_Load方法中:

myHeader.InnerHtml = "Hello";

回答by Daniel A. White

What you are probably looking for is the LiteralControlprovided by ASP.NET.

您可能正在寻找的是LiteralControlASP.NET 提供的。

See: http://msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol.aspx

请参阅:http: //msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol.aspx