是否可以通过代码从 System.Web.UI.HtmlControls.HtmlButton 设置 class 属性?
Is it possible to set a class attribute from a System.Web.UI.HtmlControls.HtmlButton though code?
我正在寻找一种方法来将 class 属性添加到按钮以便对其进行样式设置,但我无法从我的代码中弄清楚如何做到这一点。
System.Web.UI.HtmlControls.HtmlButton
有一个 AttributeCollection
属性 但它是只读的,所以对我没有用。
System.Web.UI.WebControls.Button
有一个 CssClass
属性,我需要这样的东西用于 HtmlButton
。我不能使用 WebControls
提供的按钮,因为我需要使用 HtmlButton
的 InnerHtml
属性 在按钮上放置一个图标,但我确实想要也可以设计它的样式!
有人对此有解决方案吗?
您应该可以像这样设置 css class
theHtmlButton.Attributes["class"] = "yourClass";
您可以使用此方法设置任何属性,包括您自己的自定义属性。
我正在寻找一种方法来将 class 属性添加到按钮以便对其进行样式设置,但我无法从我的代码中弄清楚如何做到这一点。
System.Web.UI.HtmlControls.HtmlButton
有一个 AttributeCollection
属性 但它是只读的,所以对我没有用。
System.Web.UI.WebControls.Button
有一个 CssClass
属性,我需要这样的东西用于 HtmlButton
。我不能使用 WebControls
提供的按钮,因为我需要使用 HtmlButton
的 InnerHtml
属性 在按钮上放置一个图标,但我确实想要也可以设计它的样式!
有人对此有解决方案吗?
您应该可以像这样设置 css class
theHtmlButton.Attributes["class"] = "yourClass";
您可以使用此方法设置任何属性,包括您自己的自定义属性。