Passing values from javascript to code behind in A

2020-02-02 00:28发布

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?

1条回答
欢心
2楼-- · 2020-02-02 01:16

Using html controls

First you use a hidden input control as:

<input type="hidden" value="" id="SendA" name="SendA" />

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"]

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>

and get it on code behind with SendA.Value;

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.

查看更多
登录 后发表回答