I have the following code line which puts a progress bar on the screen. I found the code on CodePen website and I’m still learning so please bear with me. If I change the value in data-cp-percentage then the progress bar changes to that percentage. There’s obviously CSS and Java too but I simply need to change the value in this line programatically in VB. I have tried giving the DIV an ID and but then still unsure how to change it.
<div class="counter" data-cp-percentage="3" data-cp-color="#FF675B"></div>
So I tried..
<div id="consistency" runat="server" class="counter" data-cp-percentage="3" data-cp-color="#FF675B"></div>
And in VB I tried..
consistency.data-cp-percentage=”22″
but I get error BC30456: ‘data’ is not a member of ‘System.Web.UI.HtmlControls.HtmlGenericControl’.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Front-end
<div id="myDiv" runat="server" class="counter" data-cp-percentage="3" data-cp-color="#FF675B"></div>
Code-behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load ' only setting the value once on initial load. If Not Page.IsPostBack Then Me.myDiv.Attributes("data-cp-percentage") = "1234" Else ' this would be where you could set a new value only on postbacks if you wanted End If End Sub
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0