Search code examples
c#asp.netlabelprogress-barhtmlgenericcontrol

Pass label value to progress bar value property in Asp.net


I am using a progress bar in my web project. I want to add label value getting from Code Behind to progress bar' data-percent value property. However, I am getting error such as:

Error 217 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a definition for 'text' and no extension method 'text' accepting a first argument of type 'System.Web.UI.HtmlControls.HtmlGenericControl' could be found (are you missing a using directive or an assembly reference?)

Codes are like this:

<div class="skillbar clearfix " data-percent="<asp:Label ID="lblYuzde" runat="server"></asp:Label>%">
 <div class="skillbar-title" style="background: #c0392b;"><span>TOPLAM</span>
 </div>
   <div class="skillbar-bar" style="background: #e74c3c;"></div>
   <div class="skill-bar-percent"><asp:Label ID="lblBlogAdet" runat="server" Font-Bold="true" ForeColor="navy" Font-Size="Medium"></asp:Label></div>
</div>

Screenshot of Progress Bar

Would you help me please to fix the problem in a simple way?


Solution

  • You can't do that. You are essentially putting a span inside a data-percent. You should do this sort of thing from the Code Behind.

    If you want to put the value into the data-percent attribute, I'd do something like this.

    ASPX Page

    <div class="skillbar clearfix" runat="server" id="progressBar"></div>
    

    Code Behind

    progressBar.Attributes.Add("data-percent", "your-value");
    

    See here for more.