[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Form being submitted when clicking on one of the radio buttons

Posted on 2008-11-12
4
Medium Priority
?
218 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:jianxin9
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 22944453
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
 

Author Comment

by:jianxin9
ID: 22944562
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
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 2000 total points
ID: 22944787
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
 

Author Closing Comment

by:jianxin9
ID: 31516086
I did go ahead and repost since I am now trying something sightly different.  Thanks for the info though--I appreciate it.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

831 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