Passing values ​​from javascript to code in ASP.NET

I have a variable in aspx.cs

when I click on a specific Datagrid row; Then from javascript I have to get this value and go to the aspx.cs variable.

how to do it?

+3


source to share


1 answer


Using html controls

First, you use a hidden input control:

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

      

Second, you add to this element the value you want to send by code using javascript like:

document.getElementById("SendA").value = "1";

      

And then in the response post you will receive this value as:



Request.Form["SendA"]

      

Using asp.net controls

Likewise, if you are using asp.net control you can:

<asp:HiddenField runat="server" ID="SendA" Value="" />
<script>
   document.getElementById("<%=SendA.ClientID%>").value = "1";
</script>

      

and get it by code with SendA.Value;

And of course you can use ajax calls to send over code for values ​​or a simple call url with url parameters that don't return content.

+6


source







All Articles