I'm having a small issue with my code - whenever I click submit the label in the textbox will not change to "a" and I'm not sure why.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtName.Focus();
compDate.ValueToCompare = DateTime.Now.ToString("d");
}
protected void chkCoach_CheckedChanged1(object sender, EventArgs e)
{
txtCoach.Visible = chkCoach.Checked;
}
protected void chkReferee_CheckedChanged(object sender, EventArgs e)
{
txtReferee.Visible = chkReferee.Checked;
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPass.Text.Length >= 6)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblError2.Text = "a";
if (Page.IsValid)
{
lblResult.Text = "Thank you for your input. We will be contacting you soon.";
}
if (chkCoach.Checked == true)
{
lblError2.ForeColor = System.Drawing.Color.Red;
lblError2.Text = "You must select an option";
}
int a = int.Parse(txtBirth.Text);
if (a < 18)
{
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = "You must be at least 18 years of age.";
}
}
}
Here's the other page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>HASC Registration</title>
<script type= "text/javascript">
function ClientValidate(source, args) {
if (txtPass.Text.Length >= 6) {
args.IsValid = true;
} else {
args.IsValid = false;
}
</script>
</head>
<body>
<form id="form1" runat="server" defaultbutton="btnSubmit">
<div>
<h2>
Hamilton Adult Soccer Club Registeration</h2>
<asp:Label ID="lblName" runat="server" Text="Name:"></asp:Label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqName" runat="server" ControlToValidate="txtName" SetFocusonerror="true" ErrorMessage="Name is required">Required</asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblEmail" runat="server" Text="Email:"></asp:Label>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqEmail" runat="server" Display="Dynamic" ControlToValidate="txtEmail" SetFocusonerror="true" ErrorMessage="Email is required">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regEmail" runat="server" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Email is invalid" SetFocusonerror="true"></asp:RegularExpressionValidator>
<br />
<asp:Label ID="lblGender" runat="server" Text="Gender:"></asp:Label>
<asp:DropDownList ID="lstGender" runat="server" >
<asp:ListItem Value="none">Select</asp:ListItem>
<asp:ListItem Value="M">Male</asp:ListItem>
<asp:ListItem Value="F">Female</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqGender" runat="server" ControlToValidate="lstGender" InitialValue="none" SetFocusonerror="true" ErrorMessage="Gender is required">Required</asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblBirth" runat="server" Text="Date Of Birth:"></asp:Label>
<asp:TextBox ID="txtBirth" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="reqBirth" SetFocusonerror="true" runat="server" ControlToValidate="txtBirth" ErrorMessage="Date is required">Required</asp:RequiredFieldValidator>
<asp:CompareValidator ID="compDate" runat="server" ControlToValidate="txtBirth" Type="Date" Operator="LessThan" SetFocusonerror="true"
ErrorMessage="Date invalid" Display="Dynamic"></asp:CompareValidator>
<asp:Label ID="lblError" runat="server"></asp:Label>
<br />
<asp:Label ID="lblAdd1" runat="server" Text="Address Line 1:"></asp:Label>
<asp:TextBox ID="txtAdd1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqAdd" runat="server" SetFocusonerror="true" ControlToValidate="txtAdd1" ErrorMessage="Address Line 1 is required">Required</asp:RequiredFieldValidator>
</div>
<asp:Label ID="Label1" runat="server" Text="Address Line 2:"></asp:Label>
<asp:TextBox ID="txtAdd2" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblCity" runat="server" Text="City:"></asp:Label>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqCity" runat="server" ControlToValidate="txtCity" SetFocusonerror="true" ErrorMessage="City is required">Required</asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblProvince" runat="server" Text="Province:"></asp:Label>
<asp:DropDownList ID="lstProvince" runat="server">
<asp:ListItem>AB</asp:ListItem>
<asp:ListItem>BC</asp:ListItem>
<asp:ListItem>MB</asp:ListItem>
<asp:ListItem>NB</asp:ListItem>
<asp:ListItem>NL</asp:ListItem>
<asp:ListItem>NT</asp:ListItem>
<asp:ListItem>NS</asp:ListItem>
<asp:ListItem>NU</asp:ListItem>
<asp:ListItem Selected="True">ON</asp:ListItem>
<asp:ListItem>PE</asp:ListItem>
<asp:ListItem>QC</asp:ListItem>
<asp:ListItem>SK</asp:ListItem>
<asp:ListItem>YT</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="lblPostal" runat="server" Text="Postal Code:"></asp:Label>
<asp:TextBox ID="txtPostal" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqPostal" runat="server" Display="Dynamic" ControlToValidate="txtPostal" SetFocusonerror="true" ErrorMessage="Postal code is required">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regPostal" ValidationExpression="[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d" runat="server" ControlToValidate="txtPostal" ErrorMessage="Postal code invalid, format must be A9A 9A9"></asp:RegularExpressionValidator>
<br />
<asp:Label ID="lblPhone" runat="server" Text="Phone:"></asp:Label>
<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqPhone" runat="server" Display="Dynamic" ControlToValidate="txtPhone" SetFocusonerror="true" ErrorMessage="Phone number is required">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regPhone" ValidationExpression=" ^\d{3}-\d{3}-\d{4}$" ControlToValidate="txtPhone" runat="server" ErrorMessage="Invalid phone format. Format must be xxx-xxx-xxxx"></asp:RegularExpressionValidator>
<br />
<asp:CheckBox ID="chkPlayer" runat="server" Text="Player" />
<asp:CheckBox ID="chkCoach" runat="server" Text="Coach" AutoPostBack="true" oncheckedchanged="chkCoach_CheckedChanged1" />
<asp:CheckBox ID="chkReferee" runat="server" Text="Referee" AutoPostBack="true" oncheckedchanged="chkReferee_CheckedChanged" />
<asp:Label ID="lblError2" runat="server">l</asp:Label>
<br />
<asp:TextBox ID="txtCoach" runat="server" TextMode="MultiLine" Visible="False">Please summarize your coaching experience</asp:TextBox>
<br />
<asp:TextBox ID="txtReferee" runat="server" TextMode="MultiLine"
Visible="False">Please summarize your referee experience.</asp:TextBox>
<br />
<br />
<asp:Label ID="lblPassword" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPass" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqPassword" runat="server" ControlToValidate="txtPass" SetFocusonerror="true" ErrorMessage="Password is required">Required</asp:RequiredFieldValidator>
<asp:CustomValidator ID="custPassword" runat="server" ErrorMessage="Password must be at least 6 characters"
ControlToValidate="txtPass" ClientValidationFunction="ClientValidate" SetFocusonerror="true" Display="Dynamic" onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
<br />
<asp:Label ID="lblConfirm" runat="server" Text="Confirm Password:"></asp:Label>
<asp:TextBox ID="txtConfirm" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqConfirm" runat="server" ControlToValidate="txtConfirm" SetFocusonerror="true" ErrorMessage="Confirmation password required">Required</asp:RequiredFieldValidator>
<asp:CompareValidator ID="compConfirm" Display="Dynamic" ControltoCompare="txtPass" ControlToValidate="txtConfirm" runat="server" ErrorMessage="">Password confirmation doesn't match</asp:CompareValidator>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
Text="Submit" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" />
<asp:ValidationSummary ID="valSummary" runat="server" />
<asp:Label ID="lblResult" runat="server"></asp:Label>
</form>
</body>
</html>

New Topic/Question
Reply




MultiQuote








|