从ASP代码后面将参数传递给Javascript函数 [英] Pass parameter to Javascript function from ASP code behind
问题描述
我有一个很长的过程,我想向用户显示一个进度条,我将参数(百分比)传递给我的带有母版页的Webform中的Javascript函数。
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.
我有这个:
<script type="text/javascript">
function updateProgress(percentage) {
document.getElementById('ProgressBar').style.width = percentage+"%";
}
</script>
和:
<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);
当我运行代码时,进度条永远不会从0%移动。通过使用新参数再次调用该函数,我想继续更新代码背后的完成百分比,直到达到100%。
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.
任何想法?
推荐答案
试试这种方式
string updateProgress = "18%";
ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + updateProgress + "');", true);
脚本AS
<script type="text/javascript">
function updateProgress(percentage) {
document.getElementById("ProgressBar").style.width = percentage;
}
</script>
ASPX页面
<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屋!