Same form and code... just added validation tags to make sure that the fields in the form are filled out.. tia!
=== start ====
<%@ Page Language="C#" Trace="True" %>
<script runat="server">
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("Female"
;
sex.Items.Add("Male"
;
} else {
if (married.Checked);
strMarried = "married";
//----> bombs here
else
strMarried = "single";
output.Text = "Hello, " + first_name.Text + ". You are a " + age.Text + " year old, " + strMarried + " " + sex.SelectedItem.Text + ".";
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"<html>
<head>
<title>ASP Forms</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ValidationSummary id="validSummary" runat="server" displayMode="List" showSummary="True" headerText="*** Errors On Your Form ***"></asp:ValidationSummary>
<table bgcolor="#eeeeee" border="1">
<caption>
Forms</caption>
<tbody>
<tr>
<td>
First Name</td>
<td>
<asp:Textbox id="first_name" runat="server"></asp:Textbox>
<asp:RequiredFieldValidator id="required_first_name" runat="server" display="none" errorMessage="You must enter a value for first name." controlToValidate="first_name"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Age</td>
<td>
<asp:Textbox id="age" runat="server"></asp:Textbox>
<asp:RangeValidator id="required_age_range" runat="server" display="none" errorMessage="You must enter a positive number value for age." controlToValidate="age" maximumValue="100" minimumValue="18" type="Integer"></asp:RangeValidator>
<asp:RequiredFieldValidator id="required_age" runat="server" display="none" errorMessage="You must enter a value for age." controlToValidate="age"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Married?</td>
<td>
<asp:CheckBox id="married" runat="server"></asp:CheckBox>
</td>
</tr>
<tr>
<td>
Sex</td>
<td>
<asp
ropDownList id="sex" runat="server"></asp
ropDownList>
<asp:RequiredFieldValidator id="required_sex" runat="server" display="none" errorMessage="You must select a value for sex." controlToValidate="sex"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="middle" colspan="2">
<asp:Button id="Button1" runat="server" Text="Save"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
<asp:Label id="output" runat="server"></asp:Label>
</body>
</html>
=== end code ===
=== start ====
<%@ Page Language="C#" Trace="True" %>
<script runat="server">
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("Female"
sex.Items.Add("Male"
} else {
if (married.Checked);
strMarried = "married";
//----> bombs here
else
strMarried = "single";
output.Text = "Hello, " + first_name.Text + ". You are a " + age.Text + " year old, " + strMarried + " " + sex.SelectedItem.Text + ".";
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"<html>
<head>
<title>ASP Forms</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ValidationSummary id="validSummary" runat="server" displayMode="List" showSummary="True" headerText="*** Errors On Your Form ***"></asp:ValidationSummary>
<table bgcolor="#eeeeee" border="1">
<caption>
Forms</caption>
<tbody>
<tr>
<td>
First Name</td>
<td>
<asp:Textbox id="first_name" runat="server"></asp:Textbox>
<asp:RequiredFieldValidator id="required_first_name" runat="server" display="none" errorMessage="You must enter a value for first name." controlToValidate="first_name"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Age</td>
<td>
<asp:Textbox id="age" runat="server"></asp:Textbox>
<asp:RangeValidator id="required_age_range" runat="server" display="none" errorMessage="You must enter a positive number value for age." controlToValidate="age" maximumValue="100" minimumValue="18" type="Integer"></asp:RangeValidator>
<asp:RequiredFieldValidator id="required_age" runat="server" display="none" errorMessage="You must enter a value for age." controlToValidate="age"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Married?</td>
<td>
<asp:CheckBox id="married" runat="server"></asp:CheckBox>
</td>
</tr>
<tr>
<td>
Sex</td>
<td>
<asp
<asp:RequiredFieldValidator id="required_sex" runat="server" display="none" errorMessage="You must select a value for sex." controlToValidate="sex"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="middle" colspan="2">
<asp:Button id="Button1" runat="server" Text="Save"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
<asp:Label id="output" runat="server"></asp:Label>
</body>
</html>
=== end code ===