ANP
ANP

Reputation: 15607

Add width of a div element from code behind

In the aspx page I have div with id="progressBar" and runat="server".I need to add width of the div from code behind in C#.

Can anyone help me how to do this?

Upvotes: 3

Views: 15039

Answers (3)

user405358
user405358

Reputation: 1

progressBar.Style.Add("width", "300px");

Upvotes: 0

Karan
Karan

Reputation: 3328

You can add in this way also :-

progressBar.Style.Add(HtmlTextWriterStyle.Width, "200px");

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630389

You can set it's Style property, like this:

progressBar.Style[HtmlTextWriterStyle.Width] = "200px";
//or just use a string:
progressBar.Style["width"] = "200px";

Alternatively, you can give it a CSS class, define this in your CSS:

.progress { width: 200px; }

And assign that class in your markup like this:

<div id="progressBar" runat="server" class="progress">

Or in your code-behind:

progressBar.Attributes["class"] = "progress";

Upvotes: 9

Related Questions