Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected value of a html select with asp.net

I have code below:

<select id="testSelect">     <option value="1">One</option>     <option value="2">Two</option> </select> <asp:Button ID="btnTest" runat="server" Text="Test it!" onclick="btnTest_Click" /> 

I need to get selected options' value on postback. How can I do this with asp.net?

like image 952
HasanG Avatar asked Mar 04 '10 10:03

HasanG


People also ask

How do you get the selected option value in a form?

var getValue = document. getElementById('ddlViewBy'). selectedOptions[0]. value; alert (getValue); // This will output the value selected.


1 Answers

You need to add a name to your <select> element:

<select id="testSelect" name="testSelect"> 

It will be posted to the server, and you can see it using:

Request.Form["testSelect"] 
like image 65
Kobi Avatar answered Sep 28 '22 12:09

Kobi