Form being submitted when clicking on one of the radio buttons

I have a quiz--there is a question with radio buttons--basically what I am hoping to do is make filling in a text box required if a particular radio button is selected, however when a radio button is currently selected it is submitting the quiz.    it seems that there is something weird with AutoPostBack="true" from the code below.  I'd greatly appreciate any help with this--also, it seems that the code below currently isn't really working--because if I use the back arrow to return to the quiz after it is submitted and one of the radio buttons is selected (other than the one that if the user clicks on it they need to fill out a textbox), the validator is still coming up to fill in the text box.  

 <asp:RadioButtonList ID="status" OnSelectedIndexChanged="status_SelectedIndexChanged" AutoPostBack="true" runat="server">

void status_SelectedIndexChanged (object sender, System.EventArgs e)
	{
 
		if (status.SelectedItem.Text == "guest")
		{
			RequiredFieldValidator4.Enabled = true;
		}
		else
		{
			RequiredFieldValidator4.Enabled = false;
		}
	}
 
 
Status:*<br />														
  <asp:RadioButtonList ID="status" OnSelectedIndexChanged="status_SelectedIndexChanged" AutoPostBack="true" runat="server">
			<asp:ListItem Value="undergraduate">
			</asp:ListItem>
			<asp:ListItem Value="graduate">
			</asp:ListItem>
			<asp:ListItem Value="fs">
			</asp:ListItem>
			<asp:ListItem Value="guest">
			</asp:ListItem>
		</asp:RadioButtonList>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="Server" ControlToValidate="status" ErrorMessage="Status" Text="*Status Required"></asp:RequiredFieldValidator><br />
		If you are a guest user,
		<br />
		please tell us what school are you from:<asp:TextBox ID="school" runat="server"></asp:TextBox>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="Server" ControlToValidate="school" ErrorMessage="School Name" Text="*School Name Required"></asp:RequiredFieldValidator>
 
  <br /><br />

Open in new window

jianxin9Asked:
Who is Participating?
 
Jens FiedererConnect With a Mentor Test Developer/ValidatorCommented:
This one is actually a bit tricky.

With ASP.NET, you kind of want to keep in mind what is on the client side and what is on the server side.

Your status_SelectedIndexChanged  is run on the server.  So it really has no effect UNTIL POSTBACK OCCURS.

Validation controls are capable of running client side as well as server side - so if your validation fails on the client side, NO POSTBACK OCCURS.

Oopss.....I see you are closing this!

0
 
Jens FiedererTest Developer/ValidatorCommented:
Something WEIRD?  "Submitting" is exactly what autopostback=true is SUPPOSED to do.

If you want to look at the value of thje radiobuttonlist after it is submitted by other means, don't set that.
0
 
jianxin9Author Commented:
Well  that's what I had figured, but someone from an earlier post said I needed to have that in there.  

This is what I am testing with now.  If anyone has any suggestions about how to get this to work, I would certainly appreciate them.  I do not want to submit anything--there is a submit button at the bottom of the form--I just want to make the text box required if the ListItem "guest" is selected.  Thanks!


void status_SelectedIndexChanged (object sender, System.EventArgs e)
	{
 
		if (status.SelectedItem.Text == "guest")
		{
			RequiredFieldValidator4.Enabled = true;
		}
		else
		{
			RequiredFieldValidator4.Enabled = false;
		}
	}
 	
 
Status:*<br />														
  <asp:RadioButtonList ID="status" OnSelectedIndexChanged="status_SelectedIndexChanged" runat="server">
			<asp:ListItem id="status_undergraduate" Text="undergraduate"></asp:ListItem>
			<asp:ListItem id="status_graduate" Text="graduate"></asp:ListItem>
			<asp:ListItem id="status_fs" Text="fs"></asp:ListItem>
			<asp:ListItem id="status_guest" Text="guest"></asp:ListItem>
		</asp:RadioButtonList>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="Server" ControlToValidate="status" ErrorMessage="Status" Text="*Status Required"></asp:RequiredFieldValidator><br />
		If you are a guest user,
		<br />
		please tell us what school are you from:<asp:TextBox ID="school" runat="server"></asp:TextBox>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="Server" ControlToValidate="school" ErrorMessage="School Name" Text="*School Name Required"></asp:RequiredFieldValidator>
 
  <br /><br />

Open in new window

0
 
jianxin9Author Commented:
I did go ahead and repost since I am now trying something sightly different.  Thanks for the info though--I appreciate it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.