从$ C $传递值c-背后的Javascript [英] Passing value from code-behind to Javascript
问题描述
我使用的是jQueryUI的进度向用户展示他们已经多少让文件存储使用。百分比计算code-后面应该传递给Javascript的。
I am using a jQueryUI ProgressBar to show users how much allowed file storage they have used. The percentage is calculated in code-behind and should be passed to Javascript.
在.aspx code
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
$(function () {
var pct = document.getElementById("filesPercentage").value;
$("#progressbar").progressbar({
value: pct
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
...
<input type="hidden" runat="server" id="filesPercentage" />
<div id="progressbar"></div>
...
</asp:Content>
code背后
protected void Page_Load(object sender, EventArgs e)
{
filesPercentage.Value = "85";
}
现在看来似乎不能从隐藏字段的百分比数。任何帮助将是AP preciated。
It seems like it can't get the percentage number from the hidden field. Any help would be appreciated.
推荐答案
因为你的隐藏字段是一个服务器控件这可能是因为该ID是如何产生比 filesPercentage $ C $其他东西C>(大概就像
ctl00_ctl00_filesPercentage
)
since your hidden field is a server control it could be that the ID is getting generated to something other than filesPercentage
(probably something like ctl00_ctl00_filesPercentage
)
- 您可能需要将生成的客户端ID适用于您的JavaScript
的document.getElementById(&LT;%= filesPercentage.ClientID%&gt;中)。值;
- 或者使用选择隐藏值,例如
$的另一种方式([隐藏的父元素]输入[类型=隐藏])。VAL()
- You may need to apply the generated client ID to your javascript
document.getElementById("<%=filesPercentage.ClientID%>").value;
- Or use another way of selecting the hidden value, such as
$('[hidden's parent element] input[type="hidden"]').val()
此外,它看起来像进度值期待一个号码,所以你可能需要做值:厘* 1
或值形式:parseInt( PCT)
additionally, it looks like progressbar value is expecting a number, so you may need to do value: pct * 1
or value: parseInt(pct)
http://jsfiddle.net/pxfunc/QyZSs/
这篇关于从$ C $传递值c-背后的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!