Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie question(CS1525: Invalid expression term 'else')

Status
Not open for further replies.

msingle

MIS
Jul 15, 2002
22
0
0
US
Same form and code... just added validation tags to make sure that the fields in the form are filled out.. tia!
=== start ====
<%@ Page Language=&quot;C#&quot; Trace=&quot;True&quot; %>
<script runat=&quot;server&quot;>

void Page_Load(Object Src, EventArgs E){
String strMarried;
if (!Page.IsPostBack){
//Build listbox -- this could be stored in a user control
sex.Items.Add(&quot;Female&quot;);
sex.Items.Add(&quot;Male&quot;);
} else {
if (married.Checked);
strMarried = &quot;married&quot;;
//----> bombs here
else
strMarried = &quot;single&quot;;
output.Text = &quot;Hello, &quot; + first_name.Text + &quot;. You are a &quot; + age.Text + &quot; year old, &quot; + strMarried + &quot; &quot; + sex.SelectedItem.Text + &quot;.&quot;;
}
}

</script>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;
&quot;<html>
<head>
<title>ASP Forms</title>
</head>
<body>
<form id=&quot;form1&quot; runat=&quot;server&quot;>
<asp:ValidationSummary id=&quot;validSummary&quot; runat=&quot;server&quot; displayMode=&quot;List&quot; showSummary=&quot;True&quot; headerText=&quot;*** Errors On Your Form ***&quot;></asp:ValidationSummary>
<table bgcolor=&quot;#eeeeee&quot; border=&quot;1&quot;>
<caption>
Forms</caption>
<tbody>
<tr>
<td>
First Name</td>
<td>
<asp:Textbox id=&quot;first_name&quot; runat=&quot;server&quot;></asp:Textbox>
<asp:RequiredFieldValidator id=&quot;required_first_name&quot; runat=&quot;server&quot; display=&quot;none&quot; errorMessage=&quot;You must enter a value for first name.&quot; controlToValidate=&quot;first_name&quot;></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Age</td>
<td>
<asp:Textbox id=&quot;age&quot; runat=&quot;server&quot;></asp:Textbox>
<asp:RangeValidator id=&quot;required_age_range&quot; runat=&quot;server&quot; display=&quot;none&quot; errorMessage=&quot;You must enter a positive number value for age.&quot; controlToValidate=&quot;age&quot; maximumValue=&quot;100&quot; minimumValue=&quot;18&quot; type=&quot;Integer&quot;></asp:RangeValidator>
<asp:RequiredFieldValidator id=&quot;required_age&quot; runat=&quot;server&quot; display=&quot;none&quot; errorMessage=&quot;You must enter a value for age.&quot; controlToValidate=&quot;age&quot;></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Married?</td>
<td>
<asp:CheckBox id=&quot;married&quot; runat=&quot;server&quot;></asp:CheckBox>
</td>
</tr>
<tr>
<td>
Sex</td>
<td>
<asp:DropDownList id=&quot;sex&quot; runat=&quot;server&quot;></asp:DropDownList>
<asp:RequiredFieldValidator id=&quot;required_sex&quot; runat=&quot;server&quot; display=&quot;none&quot; errorMessage=&quot;You must select a value for sex.&quot; controlToValidate=&quot;sex&quot;></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align=&quot;middle&quot; colspan=&quot;2&quot;>
<asp:Button id=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Save&quot;></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
<asp:Label id=&quot;output&quot; runat=&quot;server&quot;></asp:Label>
</body>
</html>
=== end code ===
 
You have an extra semicolon on the if-statement on the line above:
Code:
    if (married.Checked);

Since the semi-colon is a statement terminator, this means that the line afterwards is always executed, and there is nothing for your &quot;else&quot; to match up against.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top