Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set a class attribute from a System.Web.UI.HtmlControls.HtmlButton though code?

I am looking for a way to add class attributes to a button so it can be styled, but I can't figure out how to do this from my code.

The System.Web.UI.HtmlControls.HtmlButton has a AttributeCollection property but it's read-only, so that's no use to me.

System.Web.UI.WebControls.Button has a CssClass property, I need something like this for the HtmlButton. I can't use the button provided from the WebControls because I need to use the InnerHtml property of the HtmlButton to place a icon on the button, but I do want to be able to style it as well!

Does anyone have a solution for this?

like image 277
William Avatar asked Mar 23 '26 03:03

William


1 Answers

You should be able to set the css class like this

theHtmlButton.Attributes["class"] = "yourClass";

You can use this method to set any attribute, including your own custom attributes.

like image 153
Ciara Avatar answered Mar 25 '26 18:03

Ciara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!