user2748161
user2748161

Reputation: 89

How to pass Javascript Value to a method in C#

Here is my radio button list

<asp:RadioButtonList ID="geo_radio" runat="server" RepeatDirection="Vertical" RepeatLayout="Table" >                             
    <asp:ListItem Value="state">State</asp:ListItem>
    <asp:ListItem Value="county">County</asp:ListItem>
    <asp:ListItem Value="county subdivision">County Subdivision</asp:ListItem>
    <asp:ListItem Value="place">Place</asp:ListItem>
    <asp:ListItem Value="micropolitan">Micropolitan</asp:ListItem>
    <asp:ListItem Value="combined statistical area">Combined Statistical Area</asp:ListItem>
    <asp:ListItem Value="congressional districts">Congressional Districts</asp:ListItem>
    <asp:ListItem Value="Custom Region">Custom Region</asp:ListItem>
</asp:RadioButtonList>  

I am able to retrieve selected value using

$('#<%=geo_radio.ClientID%>').find('input[type="radio"]').click(function () {
    var selectedValue = $(this).val();
});

In my .aspx page I have a method FetchData(). I am calling this function on page load

protected void Page_Load(object sender, EventArgs e)
{
    FetchData();   
} 

How can I send selected radio button value to FetchData() function.

Upvotes: 0

Views: 559

Answers (2)

Aarif Qureshi
Aarif Qureshi

Reputation: 474

add selectedValue to hidden field and get hidden field value to code behind and pass it to your function

$("#hid").val(selectedValue);

hid is the id or your hidden feild

 FetchData(hid.value);

Upvotes: 0

Harold Sota
Harold Sota

Reputation: 7566

You can use a hidden field, set the value of asp hidden field, or you can use request object to retrieve the value.

The Hidden Field class

Upvotes: 1

Related Questions