Changing HTML Attributes on ASP.NET Pages in the Code Behind

Not many developers realize that you can change a plain HTML object’s attributes in the code behind without having to convert it into an ASP.NET control.

So if I have a checkbox like this:

<input type="checkbox" id="cbShowDef" name="cbShowDef"  
        onclick="javascript: show()" />

I can hide this in the code behind with:

((System.Web.UI.HtmlControls.HtmlInputCheckBox)
        Form.FindControl("cbShowDef")).Style.Add("display","none");

Leave a Comment

Your email address will not be published. Required fields are marked *