mogorilla
mogorilla

Reputation: 305

Editing elements style asp.net

So I have a progress bar which has an initial width which in this case is 40% and also an aria-valuenow="40":

<div class="progress">
 <div id="progress_bar" runat="server" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
 </div>
</div>

However when a user clicks a button I want to increment the width and the aria-valuenow to 50, is this possible in the code behind? So far I have:

protected void addTen_btn_Click(object sender, EventArgs e)
{
  progress_bar.Style.Add("width", 50);
}

Surely my code is just constantly adding a new attribute? I just want to edit the current attribute

Upvotes: 0

Views: 515

Answers (1)

A. Abramov
A. Abramov

Reputation: 1865

as the past says, the Style.Add() function does not blindly add an attribute - it checks first if it exists, and if it does, it just modifies the value. Thus, your code is pretty good. :)

progress_bar.Style.Add("width", 50);
progress_bar.Style.Add("aria-valuenow", 40); // or whatever value you want

read more about the style attribute here.

Upvotes: 1

Related Questions