.Net style control

liunx

Guest
I need to control the width of a div but I need to do it dynamicaly.

The div is also initially controlled by my stylesheet which specifies a background image. The width will grow based upon the calculation from the user input. What is happening is that after I run the page, the div retains the number from the calculation but it is not at the width calculated but always full width of the background image.

CSS code:
#scalebar {
padding: 0px;
margin-left: 2px;
position:relative;
top:5px;
background-image: url(img/scale_bar.jpg);
background-repeat:no-repeat;
text-align:right;
font-size:10px;
}

.Net code (behind)

calTotal = one + two + three + four + five + six + seven + eight + nine

scorevalueresults.Text = calTotal
scorevalueresults.Visible = True

messageText.Text = "Please scroll down to see your score."
messageText.Visible = True

If calTotal > 25 Then
barNumCal = 20 * calTotal
Else
barNumCal = 25 * calTotal
End If
If calTotal > 0 Then
scalebar.Style("width") = barNumCal
scalebar.Visible = True
scalebarNum.Visible = True
scalebarNum.Text = calTotal
End If


Rendered code:

<div id="scalebar" style="width:200;"><span id="scalebarNum">4</span></div>

I've tried making the CSS a class but the same thing happens. There is nothing else in my stylesheets that are affecting images. Anyone see what may be causing the div to not be the width specified?

thanksYep, the rendered code should look like this if you want it to do anything:

<div id="scalebar" style="width:200px;"><span id="scalebarNum">4</span></div>


You didn't specify the units for the width. In this case I added "px" for pixels. Your VB code should look like this.

calTotal = one + two + three + four + five + six + seven + eight + nine

scorevalueresults.Text = calTotal
scorevalueresults.Visible = True

messageText.Text = "Please scroll down to see your score."
messageText.Visible = True

If calTotal > 25 Then
barNumCal = 20 * calTotal
Else
barNumCal = 25 * calTotal
End If
If calTotal > 0 Then
scalebar.Style("width") = barNumCal & "px"
scalebar.Visible = True
scalebarNum.Visible = True
scalebarNum.Text = calTotal
End If
 
Back
Top