c# - Input fields inside div of the same form cannot be processed -


i have form in aspx page processed code behind c#. working fine, until needed hide or show inputs based on user needs. part works well, when put in divs, c# cannot form values anymore. here's simulation of code:

<form id="form1" runat="server">    <table width="100%" frame=box>       <tr>          <td>            <div id='firsttext' runat="server">              <table>                <tr>                   <td>                         <input name="input1" id="idinput1" runat="server" type="radio" value="someval" checked />                   </td>                </tr>              </table>             </div>          </td>       </tr>       <tr>          <td>             <div id='secondtext' runat="server">              <table>                <tr>                   <td>                         <input name="input2" id="idinput2" runat="server" type="radio" value="someval2" checked />                   </td>                </tr>              </table>             </div>          </td>       </tr>    </table> </form> 

code behind:

string selectedoption = request.form["input2"]; 

with above case, in selectionoption null. when remove divs code, fine.

any suggestion appreciated guys.

when add submit button, selectedoption value comes correctly. sample code below.

default.aspx

<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="nestedidtest.default" %>  <!doctype html>  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body> <form id="form1" runat="server">    <table width="100%" frame=box>       <tr>          <td>            <div id='firsttext' runat="server">              <table>                <tr>                   <td>                         <input name="input1" id="idinput1" runat="server" type="radio" value="someval" checked />                   </td>                </tr>              </table>             </div>          </td>       </tr>       <tr>          <td>             <div id='secondtext' runat="server">              <table>                <tr>                   <td>                         <input name="input2" id="idinput2" runat="server" type="radio" value="someval2" checked />                   </td>                </tr>              </table>             </div>          </td>       </tr>    </table>     <asp:button id="button1" runat="server" text="button" /> </form> </body> </html> 

default.aspx.cs (code behind)

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols;  namespace nestedidtest {     public partial class default : system.web.ui.page     {         protected void page_load(object sender, eventargs e)         {             string selectedoption = request.form["input2"];         }     } } 

please note added line default.aspx

<asp:button id="button1" runat="server" text="button" /> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -