?
Solved

adding a text box to a radio button list?

Posted on 2008-11-03
13
Medium Priority
?
1,147 Views
Last Modified: 2012-06-27
Hi, I have a radio button list, but was hoping to add a textbox to the last option like this.  Is this possible to do?  If this radio button is selected, is it possible to make entering info into the text box required?  Thanks!

 Status:*
undergraduate
graduate
faculty or staff
guest user (non-TWU).  What school are you from? [text box here]
<br />
																		 Status:*<br /><asp:RadioButtonList id="status" runat="server">
 
                                <asp:ListItem id="status_undergrad" runat="server" Value="undergraduate" />
                                <asp:ListItem id="status_grad" runat="server" Value="graduate" />
                                <asp:ListItem id="status_fs" runat="server" Value="faculty or staff" />
                                <asp:ListItem id="status_guest" runat="server" Value="guest user (non-TWU)" />
                            </asp:RadioButtonList>												 <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="status"
                            ErrorMessage="TWU Status" runat="Server" Text="*Status Required"></asp:RequiredFieldValidator>

Open in new window

0
Comment
Question by:jianxin9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22875649
I would think that you need to toggle the Enabled property for the RequiredFieldValidator, when the selected option in the RadioButtonList is changed.
0
 

Author Comment

by:jianxin9
ID: 22876108
Thanks!  Can anyone show me an example of how to do that?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22876159
Attach an event handler to the SelectedIndexChanged event, and change the RequiredFieldValidator.Enabled = (RadioButtonList.SelectedIndex = <index of the item that you are working with>.
0
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 

Author Comment

by:jianxin9
ID: 22876266
Thanks!   Would it look like this?  I'm not really sure....

                                <asp:ListItem id="status_undergrad" runat="server" Value="undergraduate" />
                                <asp:ListItem id="status_grad" runat="server" Value="graduate" />
                                <asp:ListItem id="status_fs" runat="server" Value="faculty or staff" />
                                <asp:ListItem id="status_guest" runat="server" Value="guest user (non-TWU)" />What school are you from?<asp:TextBox ID="status_school" runat="Server" />
                            </asp:RadioButtonList>                                                                                               <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="status"
                            ErrorMessage="TWU Status" runat="Server" Text="*Status Required" Enabled = (RadioButtonList.SelectedIndex = <status>
							</asp:RequiredFieldValidator>

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22876341
That is the fun part of trying to figure out ASP.NET--trying to find just the right form.

An answer can be found here:

ListControl..::.SelectedIndexChanged Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged.aspx
0
 

Author Comment

by:jianxin9
ID: 22876435
thanks!  yeah, i am still confused about how to put it all together--thanks for the link
0
 

Author Comment

by:jianxin9
ID: 22878807
Hmmm...I am still stumped on this--if anyone could formulate an example of how this might work using my code I would really appreciate it!  Thanks!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 22879677
That someone is going to be me, and I am going to try to get you where you need to be, without doing the work for you.

Important points from the article:

1) Attach an event handler in HTML for the SelectedIndexChanged event

<asp:RadioButtonList id="RadioButtonList1"
            OnSelectedIndexChanged="Index_Changed"
            AutoPostBack="true"
            runat="server"/>

2) Define the event handler in the code-behind

   VB.NET:
   Sub Index_Changed(sender As Object, e As EventArgs)        
        Label1.Text = "You selected " & RadioButtonList1.SelectedItem.Text & _
            " with a value of : " & RadioButtonList1.SelectedItem.Value & "."
    End Sub

    C#:
    void Index_Changed(Object sender, EventArgs e) {

       Label1.Text = "You selected " + RadioButtonList1.SelectedItem.Text +
                     " with a value of $" + RadioButtonList1.SelectedItem.Value +
                     ".";

    }
0
 

Author Comment

by:jianxin9
ID: 22879989
I do appreciate the help--thank you.   Okay, I am getting errors when I load the page--but this is what I'm trying. Am I on the right track at all?
Info before closing script tag:
} 
    // Allow the user to enter in their school information if from another institution
 
 void Index_Changed(Object sender, EventArgs e) {
 
       Label1.Text = "You selected " + RadioButtonList1.SelectedItem.Text +
                     " Please tell us what school you are from" + RadioButtonList1.SelectedItem.Value +
                     ".";
 
    }
 
								
 
Status:*<br /><asp:RadioButtonList id="status" runat="server">
 
                                <asp:ListItem id="status_undergrad" runat="server" Value="undergraduate" />
                                <asp:ListItem id="status_grad" runat="server" Value="graduate" />
                                <asp:ListItem id="status_fs" runat="server" Value="faculty or staff" />
                                 <asp:ListItem id="status_guest" OnSelectedIndexChanged="Index_Changed"
            AutoPostBack="true" runat="server" Value="guest user (non-TWU)" /></asp:RadioButtonList>   What school are you from?<asp:Label id="Label1" runat="server"/>
                                                                 				 <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="status"
                            ErrorMessage="TWU Status" runat="Server" Text="*TWU Status Required"></asp:RequiredFieldValidator><br />

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22880104
That is the right track, but you are referencing Label1, which you don't have on the page, so you need to change the Index_Changed event handler to do what you need, which is to look at the RadioButtonList's selected item, and determine how to set RequiredFieldValidator.Enabled.
0
 

Author Comment

by:jianxin9
ID: 22880402
Hmm...well, I'm confused about the example--where does the text box come in?

Is this any closer?  Sorry--I'm pretty new to this and very lost.
Info before closing script tag:
} 
    // Allow the user to enter in their school information if from another institution
 
 void Index_Changed(Object sender, EventArgs e) {
 
       Label1.Text = "You selected " + status_guest.SelectedItem.Text +
                     " Please tell us what school you are from" + status_guest.SelectedItem.Value +
                     ".";
 
    }
 
                                                                
 
Status:*<br /><asp:RadioButtonList id="status" runat="server">
 
                                <asp:ListItem id="status_undergrad" runat="server" Value="undergraduate" />
                                <asp:ListItem id="status_grad" runat="server" Value="graduate" />
                                <asp:ListItem id="status_fs" runat="server" Value="faculty or staff" />
                                 <asp:ListItem id="status_guest" OnSelectedIndexChanged="Index_Changed"
            AutoPostBack="true" runat="server" Value="guest user (non-TWU)" /></asp:RadioButtonList>   What school are you from?<asp:Label id="Label1" runat="server"/>
                                                                                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="status"
                            ErrorMessage="TWU Status" runat="Server" Text="*TWU Status Required"></asp:RequiredFieldValidator><br />

Open in new window

0
 

Author Comment

by:jianxin9
ID: 22886964
For anyone that can help with this--is this any closer?  Thanks!
Hidden Code:
 
}       
         
         //Give users the option to enter school information
         Protected Sub rbl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbl1.SelectedIndexChanged
     
  If rblAns.SelectedValue = "status_guest" Then
      ctlValidation.enabled = True
  else
      ctlValidation.enabled = False
  End If
 
End Sub
</script>
 
 
 
 
      Status:*<br /><asp:RadioButtonList id="status" runat="server">
 
                                <asp:ListItem id="status_undergrad" runat="server" Value="undergraduate" />
                                <asp:ListItem id="status_grad" runat="server" Value="graduate" />
                                <asp:ListItem id="status_fs" runat="server" Value="faculty or staff" />
                                 <asp:ListItem id="status_guest" runat="server" Value="guest user (non-TWU)" /></asp:RadioButtonList>   
 
                                                                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="status"
                            ErrorMessage="Status" runat="Server" Text="*TWU Status Required"></asp:RequiredFieldValidator><br />
                                                        What school are you from?<asp:TextBox ID="school" runat="Server" />

Open in new window

0
 

Author Closing Comment

by:jianxin9
ID: 31512727
thanks for the help
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I have a Synology DS212+ NAS.  These are not only great for backup and normal NAS stuff, but also for delivering media throughout your home or LAN via DLNA.  I copied my whole audio collection from iTunes over to the box, but couldn't figure out how…
Users will learn how to set proper sequence settings, scale images, paste attributes, add transitions, fades, and music. Open up Final Cut Pro 7 and Create a new Project: Set the Sequence Settings. a) Click File > Easy Setup > Format > Apple ProRe…
Viewers will learn how to use Macros for greater control over Rack parameters in Ableton Live. Group devices into a Rack by selecting them and pressing Command-G (Ctrl-G on PC): Control-click (Right Click on PC) a parameter to access pop-up menu, …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question