Add div element width from code

On an aspx page, I have a div with id="progressBar"and runat="server". I need to add div width from code located in C #.

Can someone help me how to do this?

+3
source share
3 answers

You can set a Styleproperty , for example:

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 this class in your markup as follows:

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

Or in your code:

progressBar.Attributes["class"] = "progress";
+8
source

You can also add: -

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

0
source

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

0

Source: https://habr.com/ru/post/1757113/


All Articles