Passing value from Javascript function to CS file


I am setting a value of a radio button in a javascript function.

Now, to save this value of radio button in database, I have code which is in the aspx.cs file.

How do I pass this value of radio button to aspx.cs file?

Who is Participating?
Amandeep Singh BhullarConnect With a Mentor Commented:
Any value that is set through a JavaScript is not readable in .cs fle
But there is one trick

Place a hidden textbox on page.
Make it hidden with style tag.

Before posting a page back, set the value of textbox as of selected value of radio button.
Value of text box is readable at server side.
Use textbox as

<input type="text" runat="server" id="txthidden" style="display:none" />

Hope this will help u
Om PrakashCommented:
Radio button is server control or HTML controls?
If it is codebehind, then you can directly access from id, in case of HTML control:

(1) Edit the HTML code to include the attribute runat="server" in the
opening tag of the HTML control. For example for a table it might be:
<TABLE id="Table1" ...(other attributes) ... runat="server">

(2) Then you need to include the namespace "System.Web.UI.HtmlControls"
in the code behind (e.g. in VB the directive Imports
use hidden controls.
All Courses

From novice to tech pro — start learning today.