mrmcg
mrmcg

Reputation: 193

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;

Upvotes: 1

Views: 2988

Answers (1)

Kuzgun
Kuzgun

Reputation: 4737

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"]

Upvotes: 1

Related Questions