简体   繁体   中英

RadioButtonList Textbox nested… C#

I have been trying to input a text box control inside a RadioButtonList control in C#. Below is the way I have been doing it, but I have been trying to gather the values in the textboxes and it always passes null value even when data is in the textbox. Any ideas or suggestions?

--aspx

        <asp:RadioButtonList ID="rblContactMethod" runat="server" OnSelectedIndexChanged="rblContactMethod_OnSelectedIndexChanged" GroupName="grpContactMethod" AutoPostBack="True">
        <asp:ListItem Value="All" Text="All">All</asp:ListItem>
        <asp:ListItem Value="Range">Range: <input name="txtDateRange1" id="txtDateRange1" type="text" /> to <input name="txtDateRange2" id="txtDateRange2" type="text" /></asp:ListItem>         
        <asp:ListItem Value="Single" Text="SingleDate">Single Date: <input id="txtSingleDate" type="text" /></asp:ListItem>
        </asp:RadioButtonList>

-- aspx.cs I even tried this:

  TextBox txt1 = FindControl("txtDateRange1") as TextBox;
  TextBox txt2 = FindControl("txtDateRange2") as TextBox;

Your inputs are not aspx controls and they are not having attribute runat="server". This means you cannot reach them on backend. You need to either make them accesible, or get the value after postback like:

Request.Form["txtDateRange1"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM