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?
The returned value from JavaScript function will be saved in a HiddenField and then will be sent to Code Behind (Server Side) function through PostBack (Form Submission) in ASP.Net using C# and VB.Net. The HTML Markup consists of an ASP.Net Button btnConfirm.
You cannot directly access the javascript variables in your code behind. You'd need to send the information to the server, for example by sending them back as form fields or query string parameters via an ajax request.
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"]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With