[英]Not able to use javascript variable in code behind in C#
Guys I am using a jquery price range slider for getting Price range from user.But the problem is that the Price range selected by user on slider I have to use that in code behind.My code is like this: My java script: 伙计们,我正在使用一个jQuery的价格范围滑块来从用户那里获取价格范围。但是问题是用户在滑块上选择的价格范围我必须在后面的代码中使用它。我的代码是这样的:我的Java脚本:
<script type="text/javascript">
//adding load class to body and hide page
document.documentElement.className += 'loadstate';
</script>
<script type ="text/javascript" >
var str1= document.getElementById("amt3").value;
var str2= document.getElementById("amt4").value;
document.getElementById("hf1").value = str1;
document.getElementById("hf2").value = str2;
</script>
</head>
My Html code is like this: 我的HTML代码是这样的:
<asp:HiddenField ID="hf1" runat="server" />
<asp:HiddenField ID="hf2" runat="server" />
<div class="form-row row-fluid">
<div class="span12">
<div class="row-fluid">
<label class="form-label span4" for="slider">
Range slider</label>
<div class="span8">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate >
<asp:HiddenField ID="HiddenField1" runat="server" />
<div id="slider-range" class="slider" >
</div>
<input type="text" id="amount1" style="border: 0; color: #ED7A53; font-weight: bold;
box-shadow: none;" />
<input type="text" id="amt3" style="border: 0; color: #ED7A53; font-weight: bold;
box-shadow: none;" />
<input type="text" id="amt4" name="amt4" style="border: 0; color: #ED7A53;
font-weight: bold; box-shadow: none;" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
and My code Behind is like this: 我的背后代码是这样的:
protected void lnkFilter_Click1(object sender, EventArgs e)
{
string str= hf1.Value;
if (WebHelper.Cast(amt2.Value, 0) != 0)
{
Fill();
}
}
But the Problem is hf1 (hidden field) is getting empty string value.Please help me in this and suggest me a solution how to use selected range on jquery slider in code behind file. 但是问题是hf1(隐藏字段)正在获取空字符串值。请帮我解决这个问题并为我提供一个解决方案,该方法如何在文件后面的代码中使用jquery滑块上的选定范围。
您应该将“隐藏”值移动到“更新”面板中,因为它们不会在部分更新时被发布回服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.