如何在 C# 代码隐藏文件中向面板 (div) 添加标题属性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1187802/
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-06 10:21:33  来源:igfitidea点击:

how do i add a title attribute to a panel (div) in the c# code behind file?

c#.net

提问by ErnieStings

ASP.NET C#

ASP.NET C#

how do i add a title attribute to a panel (div) in the c# code behind file?

如何在 C# 代码隐藏文件中向面板 (div) 添加标题属性?

回答by Tim S. Van Haren

In your aspx page:

在您的 aspx 页面中:

<asp:panel id="MyPanel" runat="server"></asp:panel>

In your codebehind:

在您的代码隐藏中:

protected void Page_Load(object sender, EventArgs e)
{
    MyPanel.Attributes.Add("title", "A title for this div");
}

回答by M4N

Add a runat="server" attribute to your div, then you can access it like any other ASP.NET control.

将 runat="server" 属性添加到您的 div,然后您就可以像访问任何其他 ASP.NET 控件一样访问它。

markup:

标记:

<div id="myDiv" runat="server"></div>

code-behind:

代码隐藏:

myDiv.Attributes["title"] = "some title";