title: How can I get the text of the selected item in an html select element?
body: <p>I need the value of the selected item in an html select element. <a href="https://stackoverflow.com/questions/2378338/how-to-get-selected-value-of-a-html-select-with-asp-net">Here</a> the accepted answer recommends doing it like so:</p>
  
  <pre><code>Request.Form["testSelect"]
  </code></pre>
  
  <p>So in my case, I've got this html select element:</p>
  
  <pre><code>&lt;select name="subcategory" color="&lt;%=Session("TextColor")%&gt;" style="font: 8pt arial" onchange="UpdateFlag=true;"&gt;
      &lt;% if Not IsNewBusiness then %&gt;
        &lt;option &lt;% If subcategory = "0" Then Response.Write(" selected")%&gt; value="0"&gt;Existing
        &lt;option &lt;% If subcategory = "1" Then Response.Write(" selected")%&gt; value="1"&gt;Organic Growth
      &lt;% else %&gt;
        &lt;option &lt;% If subcategory = "0" Then Response.Write(" selected")%&gt; value="0"&gt;New
        &lt;option &lt;% If subcategory = "1" Then Response.Write(" selected")%&gt; value="1"&gt;Assumed
      &lt;% end if %&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Yet the design-time compiler is not happy with it, as can be seen by the squiggles beneath "Request.Form" and the whiteness of "subcategory":</p>
  
  <p><a href="https://i.stack.imgur.com/SnYDc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SnYDc.png" alt="enter image description here"></a></p>
  
  <p>What do I need to do to grab that value from VB.NET?</p>
  
  <h2>UPDATE</h2>
  
  <p>When I tried what Sailor suggested in his answer (added "runat="server"" to the html select element), I got:</p>
  
  <pre><code>Server Error in '/EMS/customerreportingnet' Application.
  --------------------------------------------------------------------------------
  
  Parser Error 
  Description: An error occurred during the parsing of a resource required to service this request. Please review the following 
  
  specific parse error details and modify your source file appropriately. 
  
  Parser Error Message: Server tags cannot contain &lt;% ... %&gt; constructs.
  
  Source Error:    
  
  Line 744:                                        &lt;/td&gt;
  Line 745:                                        &lt;td nowrap align="left" valign="top"&gt;
  Line 746:                                            &lt;select runat="server" name="subcategory" color="&lt;%=Session
  
  ("TextColor")%&gt;" style="font: 8pt arial" onchange="UpdateFlag=true;"&gt;
  Line 747:                                                &lt;% If Not IsNewBusiness Then%&gt;
  Line 748:                                                &lt;option &lt;% If Subcategory = "0" Then Response.Write(" selected")%&gt; 
  
  value="0"&gt;     
  
  Source File: /EMS/customerreportingnet/pages/custmaint_entry.aspx    Line: 746     
  
  --------------------------------------------------------------------------------
  Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
  </code></pre>
  
  <p>Removing it obliterated the err.</p>
  
  <h2>UPDATE 2</h2>
  
  <p>This:</p>
  
  <pre><code>Subcategory = Request.Form.Item("selectSubcategory")
  </code></pre>
  
  <p>...is giving me the index of the selected item (such as "0"); how can I get the actual text instead?</p>
  
  <h2>UPDATE 3</h2>
  
  <p>It turns out that it's not really giving me the index of the selected item, after all - it is simply giving me "0" always - whether the first (0th) or second (1st) option is selected.</p>
  
  <p>If I try what is mentioned at the outset, using this kind of code:</p>
  
  <pre><code>Subcategory = Request.Form["selectSubcategory"]
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Compilation Error 
  Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
  
  Compiler Error Message: BC30311: Value of type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'String'.
  
  Source Error:
  
  Line 90:         CustNo = Request.Form.Item("CustNo")
  Line 91:         'Subcategory = Request.Form.Item("selectSubcategory").ToString() '&lt;= question at https://stackoverflow.com/questions/42655000/how-can-i-reference-the-selected-item-in-an-html-select-element-vb-net
  Line 92:         Subcategory = Request.Form["selectSubcategory"]
  Line 93:         AutoID = Request.Form.Item("AutoID")
  Line 94:         ReturnMsg = ""
  
  Source File: C:\Users\cshannon\Source\Workspaces\CSReports\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx    Line: 92
  </code></pre>
  
  <p>That's why I went the other route, with:</p>
  
  <pre><code>Subcategory = Request.Form.Item("selectSubcategory").ToString()
  </code></pre>
  
  <p>...but that's not quite cutting the mustard, either (just returning 0 always).</p>