最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Passing values from javascript to code behind in ASP.NET - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Oct 6, 2016 at 5:41 Vikrant 5,03618 gold badges51 silver badges74 bronze badges asked Jan 30, 2013 at 11:46 OutOut 6752 gold badges13 silver badges20 bronze badges 2
  • 2 what exactly you want to do, provide some code, what exactly you want to do with that variable at server side? – Rahul R. Commented Jan 30, 2013 at 11:50
  • There are many ways to do this however if you tell the purpose someone might advise you an alternate easier method. – Zo Has Commented Jan 30, 2013 at 13:48
Add a comment  | 

1 Answer 1

Reset to default 13

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.

发布评论

评论列表(0)

  1. 暂无评论