将参数从后面的 ASP 代码传递给 Javascript 函数 [英] Pass parameter to Javascript function from ASP code behind

查看:31
本文介绍了将参数从后面的 ASP 代码传递给 Javascript 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的过程,我想向用户显示一个进度条,在那里我将参数(百分比)传递给带有母版页的 Web 表单中的 Javascript 函数.

我有这个:

和:

<div id="ProgressBar" class="progress-bar" role="progressbar" runat="server"aria-valuemin="0" aria-valuemax="100" style="width: 0%">

在我的代码隐藏中,我有这个将参数传递给函数:

//报告进度>>~ 18%字符串 updateProgress = "18";ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);

当我运行代码时,进度条永远不会从 0% 开始移动.我想通过使用新参数再次调用该函数来不断更新后面代码的完成百分比,直到达到 100%.

我浏览了论坛,但我看不出我需要做什么才能让它发挥作用.

有什么想法吗?

解决方案

试试这个方法

 string updateProgress = "18%";ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);

脚本AS

 

ASPX 页面

 

<div id="ProgressBar" runat="server" class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100"样式=宽度:0px;">

I have a long process and I want to show a user a progress bar where I pass a parameter (percentage) to a Javascript function in my Webform with masterpage.

I have this:

<script type="text/javascript"> 
        function updateProgress(percentage) {          
            document.getElementById('ProgressBar').style.width = percentage+"%";
        }
</script>

and:

<div class="progress progress-striped active progress-success" style="height: 43px">
      <div id="ProgressBar" class="progress-bar" role="progressbar" runat="server"
          aria-valuemin="0" aria-valuemax="100" style="width: 0%">
      </div>
</div>

In my code-behind, I have this to pass a parameter to the function:

// Report progress >> ~ 18%                   
string updateProgress = "18";
ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);

As I run the code, the progressbar never moves from 0%. I would like to keep updating the percentage completion from code behind until it reaches 100% by calling the function again with new parameters.

I have looked through forums but I cant see what I need to to to make it work.

Any ideas?

解决方案

Try this way

    string updateProgress = "18%";
    ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);

Script AS

   <script type="text/javascript">
    function updateProgress(percentage) {
        document.getElementById("ProgressBar").style.width = percentage;
    }
  </script>

ASPX page

   <div class="progress progress-striped active progress-success" style="height: 43px">
        <div id="ProgressBar" runat="server" class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100"
            style="width: 0px;" >
        </div>
    </div>

这篇关于将参数从后面的 ASP 代码传递给 Javascript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
C#/.NET最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆