简体   繁体   English

进度栏,使用样式更新进度

[英]Progress Bar using Style to Update Progress

I'm creating a progress bar using a div with class from bootstrap css. 我正在使用带有来自Bootstrap CSS的类的div创建进度条。

I'm actually dynamically setting the value for the progress bar using JQuery. 我实际上是使用JQuery动态设置进度条的值。

The process is getting the value for the progress bar then storing it into a HiddenField then retrieving this value from the HiddenField. 该过程将获取进度条的值,然后将其存储到HiddenField中,然后从HiddenField中检索该值。 Lastly, using JQuery to change the width and aria-valuenow for the progress bar. 最后,使用JQuery更改进度栏的宽度和aria-valuenow。

The issue is that, the progress bar is still set to 0 in terms of width and aria-valuenow. 问题在于,进度栏在宽度和aria-valuenow方面仍设置为0。 Could anyone please help me with that? 有人可以帮我吗?

Codes for progress bar, 进度条代码,

<div class="skills-wrapper wow animated bounceIn animated animated" data-wow-delay="0.2s" style="visibility: visible; animation-delay: 0.2s; animation-name: bounceIn;">
  <h3 class="heading-progress">Login & Login Failures (%) <span class="pull-right" runat="server" id="Lbl_PercentageCheck"></span></h3>
     <div class="progress">
        <div class="progress-bar" runat="server" aria-valuemax="100" aria-valuemin="0" role="progressbar"></div>
  </div>               

Codes in script tag, 脚本标签中的代码,

<script type="text/javascript">
    $(document).ready(function () {
        var hfPercentage = parseFloat($('#hf_Percentage').val());
        $('.progress-bar').css('width', hfPercentage + '%').attr('aria-valuenow', hfPercentage);
    });
</script>

And finally the HiddenField, 最后是HiddenField,

<asp:HiddenField runat="server" ID="hf_Percentage" />

Im actually using a WebForm with a MasterPage, and the position of the HiddenField and Javascript is down below.. Whereas the progress bar is placed nearer to the bottom before the closing tag of the ContentPlaceHolder. 我实际上是将WebForm与MasterPage一起使用,并且HiddenField和Javascript的位置在下面。.而进度条位于ContentPlaceHolder的结束标记之前靠近底部的位置。

捕获

I followed this link but it didn't work out.. This here 我跟着这个链接,但它没有工作了.. 这这里

I was thinking could it be the script not running at PageLoad or? 我在想这可能是脚本未在PageLoad上运行吗?

Any help appreciated please.. Thank you! 任何帮助,请感激..谢谢!

Image of it 图片

图片

Codes Behind: 背后的代码:

    int countLogin = al.pieLogin(username);
    int countLogout = al.pieLogout(username);
    int countFailure = al.pieFailure(username);
    int countChangePW = al.pieChangePW(username);

    //If more than 20%, prompt Admin to perform actions.

    double overallPercentageFull = Math.Round((countFailure * 100.0) / (countFailure + countLogin), 1);

    Lbl_PercentageCheck.InnerText = overallPercentageFull.ToString() + "%";
    //Lbl_PercentageCheck.Style.Add("width", (overallPercentageFull).ToString() + "%");
    //Lbl_PercentageCheck.Attributes.Add("aria-valuenow", overallPercentageFull.ToString());

    hf_Percentage.Value = overallPercentageFull.ToString();

Oke found your problem. 奥克发现了你的问题。 The ToString() method creates a string with a comma seperator. ToString()方法使用逗号分隔符创建一个字符串。 The progress-bar only accepts a double with a dot seperator. 进度栏仅接受带有点分隔符的双精度。

This works. 这可行。

  1. Add Id to the progress control. 将ID添加到进度控件。

     <div class="progress"> <div class="progress-bar" runat="server" ID="ProgressBar" aria-valuemax="100" aria-valuemin="0" role="progressbar"> </div> </div> 
  2. Use this control in the code-behind an assign the values. 在代码后面的代码中使用此控件来分配值。

     ProgressBar.Style.Add("width", overallPercentageFull.ToString("F1") + "%"); ProgressBar.Attributes.Add("aria-valuenow", overallPercentageFull.ToString("F1")); 
  3. Get rid of the hiddenField and other JS. 摆脱hiddenField和其他JS。

I don't think anyone would read this because the question is rather lengthy. 我认为没人会读这个,因为这个问题相当冗长。 But i managed to fix everything without using JQuery but simply using code from behind. 但是我设法不使用JQuery而是只使用后面的代码来修复所有问题。

Spent hours trying to fix this but the solution was simply setting the style -> width of the div progress bar 花了几个小时尝试解决此问题,但解决方案只是设置样式-> div进度条的宽度

ProgressBarDiv.Style.Add("width", (overallPercentageFull).ToString() + "%");

Code in aspx.cs: aspx.cs中的代码:

    int countLogin = al.pieLogin(username);
    int countLogout = al.pieLogout(username);
    int countFailure = al.pieFailure(username);
    int countChangePW = al.pieChangePW(username);

    //If more than 20%, prompt Admin to perform actions.

    double overallPercentageFull = Math.Round((countFailure * 100.0) / (countFailure + countLogin), 1);

    Lbl_PercentageCheck.InnerText = overallPercentageFull.ToString() + "%";
    ProgressBarDiv.Style.Add("width", (overallPercentageFull).ToString() + "%");
    ProgressBarDiv.Attributes.Add("aria-valuenow", overallPercentageFull.ToString());

    if (overallPercentageFull < 15.0)
    {
        Lbl_PercentageCheck.Style.Add("ForeColor", "green");

    }
    else if (overallPercentageFull >= 15.0)
    {
        Lbl_PercentageCheck.Style.Add("ForeColor", "red");
    }

Code in WebForm: WebForm中的代码:

<div class="col-md-12">
    <div class="skills-wrapper wow animated bounceIn animated animated" data-wow-delay="0.2s" style="visibility: visible; animation-delay: 0.2s; animation-name: bounceIn;">
        <h3 class="heading-progress">Login & Login Failures (%) <span class="pull-right" runat="server" id="Lbl_PercentageCheck"></span></h3>
           <div class="progress">
               <div class="progress-bar" aria-valuemax="100" aria-valuemin="0" style="width: 0%" runat="server" id="ProgressBarDiv" role="progressbar">
               </div>
            </div>         
    </div>

Finally, 最后,

这里

This is not an answer. 这不是答案。 This is a response to see code from @domster 这是从@domster看代码的回应

Tried the solution and cannot get it to work. 尝试过解决方案,无法使其正常工作。 Here is my html: 这是我的html:

 <div>
     <h3 class="heading-progress">Progress(%) <span class="pull-right" runat="server" id="Lbl_PercentageCheck"></span></h3>
     <div class="progress">
           <div class="progress-bar" aria-valuemax="100" aria-valuemin="0" style="width: 0%" runat="server" id="ProgressBarDiv" role="progressbar">
           </div>
        </div>   
 </div>

In the codebehind: 在后面的代码中:

    protected void btnImport_ServerClick(object sender, EventArgs e)
    {
        HasUpload = true;

        for(int z = 1000;z < 3322;z++)
        {
            double overallPercentageFull = Math.Round((z * 100.0) / 3322, 1);
            Lbl_PercentageCheck.InnerText = overallPercentageFull.ToString() + "%";
            ProgressBarDiv.Style.Add("width", (overallPercentageFull).ToString() + "%");
            ProgressBarDiv.Attributes.Add("aria-valuenow", overallPercentageFull.ToString());
            if (overallPercentageFull < 15.0)
            {
                Lbl_PercentageCheck.Style.Add("ForeColor", "green");

            }
            else if (overallPercentageFull >= 15.0)
            {
                Lbl_PercentageCheck.Style.Add("ForeColor", "red");
            }
            Thread.Sleep(200);
            Lbl_PercentageCheck.InnerText = overallPercentageFull.ToString() + "%";
            ProgressBarDiv.Style.Add("width", (overallPercentageFull).ToString() + "%");
            ProgressBarDiv.Attributes.Add("aria-valuenow", overallPercentageFull.ToString());

            if (overallPercentageFull < 15.0)
            {
                Lbl_PercentageCheck.Style.Add("ForeColor", "green");

            }
            else if (overallPercentageFull >= 15.0)
            {
                Lbl_PercentageCheck.Style.Add("ForeColor", "red");
            }
        }

It updates the bar once at the end. 最后一次更新一次酒吧。 I even tried putting it in an Update Panel. 我什至尝试将其放在“更新面板”中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM