How to get selected value of a html select with asp.net
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"]
I've used this solution to get what you need.
Let'say that in my .aspx code there's a select list runat="server":
<select id="testSelect" runat="server" ClientIDMode="Static" required> <option value="1">One</option> <option value="2">Two</option></select>
In my C# code I used the code below to retrieve the text and also value of the options:
testSelect.SelectedIndex == 0 ? "uninformed" : testSelect.Items[testSelect.SelectedIndex].Text);
In this case I check if the user selected any of the options. If there's nothing selected I show the text as "uninformed".
If you would use asp:dropdownlist
you could select it easier by testSelect.Text
.
Now you'd have to do a Request.Form["testSelect"]
to get the value after pressed btnTes
.
Hope it helps.
EDIT: You need to specify a name
of the select (not only ID) to be able to Request.Form["testSelect"]