Tuesday, March 11, 2014

How to change css from Code Behind

Normally css is changed though jQuery but in this tutorial I will show you how you can change a control css from code behind.

First we need to find the control

HtmlControl myControl1 = (HtmlControl)Page.Master.FindControl("Label1");
         
            myControl1.Attributes.Add("style", "display:none");


In the above example we are first finding an element Label1 which is inside our master page, after finding the control we are saving it in myControl1 who's type is HtmlControl

Now using Control1.attributes.Add()

We can add any css

I hope it was informative for you and I would like to Thank you for reading         

No comments:

Post a Comment