从JavaScript传递值code在ASP.NET背后 [英] Passing values from javascript to code behind in ASP.NET
问题描述
我在aspx.cs变量当我点击DataGrid中特定行,然后从JavaScript的我应该得到的价值和传递到aspx.cs变量,如何做到这一点?你可以帮我吗?
I have a variable in aspx.cs when i click the datagrid particular row then from the javascript i should get that value and pass into aspx.cs variable, how to do this? could you please Help me?
推荐答案
首先,你使用隐藏的输入控制为:
Using html controls
First you use a hidden input control as:
<input type="hidden" value="" id="SendA" name="SendA" />
二,你添加到您的控制喜欢在code发送的背后使用JavaScript作为值:
Second you add to that control the value you like to send on code behind using javascript as:
document.getElementById("SendA").value = "1";
,然后回来后你得到的价值为:
And then on post back you get that value as:
Request.Form["SendA"]
使用asp.net控件
同样的方式,如果你使用asp.net控制可为:
Using asp.net Controls
The same way if you use asp.net control can be as:
<asp:HiddenField runat="server" ID="SendA" Value="" />
<script>
document.getElementById("<%=SendA.ClientID%>").value = "1";
</script>
和得到它code与 SendA.Value落后;
当然,你可以使用Ajax调用价值上落后code,或URL参数不返回内容简单的调用URL发送。
And of course you can use ajax calls to send on code behind values, or simple call url with url parameters that return no content.
这篇关于从JavaScript传递值code在ASP.NET背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!