Validation Summary Control Not Displaying Errors

569 views Asked by At

I really don't know why this is happening. Validation Summaries seem like very basic controls. After I click the "Submit" button, the individual error messages appear nex to the fields (for instance, when a field is required, the error message saying "Field Required" appears next to the textbox), but nothing appears where my validation summary should be. I don't have any Validation Groups because I want to validate everything on the page. Everything on my page looks and works fine. I just can't seem to figure out what could possibly be preventing the summary from displaying. The validation summary is at the top of the page. Here's my code:

<form id="form1" runat="server">

  <asp:ValidationSummary
  id="valSum" 
  DisplayMode="BulletList"
  runat="server"/>

<div id ="name">




 <asp:Label
 id="lblFirstName"
 Text="First Name:"
 AssociatedControlID="txtFirstName"
 Runat="server" />
 <br />
 <asp:TextBox
 id="txtFirstName"
 Runat="server" />
 <asp:RequiredFieldValidator
 id="reqFirstName"
 ControlToValidate="txtFirstName"
 Text="(Required)"
 Runat="server" />
    </div>
 <div>
 <asp:Label
 id="lastName"
 text="Last Name:"
 runat="server" />
 <br />
 <asp:TextBox
 id="txtLastName"
 Runat="server" />
 <asp:RequiredFieldValidator
 id="reqLastName"
 ControlToValidate="txtLastName"
 Text="(Required)"
 Runat="server" />

 <br /><br />

 <asp:Label
 id="city"
 text="City:"
 runat="server" />
 <br />
<asp:TextBox
 id="txtCity"
 Runat="server" />
 <asp:RequiredFieldValidator
 id="reqCity"
 ControlToValidate="txtCity"
 Text="(Required)"
 Runat="server" />

 <br /><br />

 <asp:Label
 id="state"
 text="State:"
 runat="server" />
 <br />
<asp:TextBox
 id="valState"
 MaxLength="2"
 Width="20"
 Runat="server" />
 <asp:CustomValidator
 id="reqState"
 ControlToValidate="valState"
 OnServerValidate="stateArrayCheck"
 Text="Please enter a valid U.S. State (using all caps)"
 Runat="server" />

 <br /><br />

 <asp:Label
 id="Label1"
 text="Zip Code"
 runat="server" />
 <br />
<asp:TextBox
 id="zipText"
 Runat="server"
 width="40" />
 <asp:RangeValidator
 id="reqZip"
 ControlToValidate="zipText"
 Text="Must be a valid zip code between 40000 and 59000"
 MinimumValue="40000"
 MaximumValue="59000"
 Runat="server" />

 <br /><br />

 <asp:Label 
 id="lblPhone"
 Text="Phone Number:"
 AssociatedControlID="txtPhone"
 Runat="server" />
 <br />
 <asp:TextBox
 id="txtPhone"
  Runat="server" />
 <asp:RegularExpressionValidator
 id="regPhone"
 ControlToValidate="txtPhone"
 Text="(Invalid Phone Number. Please use the format 555-555-5555)"
 ValidationExpression="[0-9]{3}-[0-9]{3}-[0-9]{4}"
 Runat="server" /> 

 <br /><br />

 <asp:Label 
 id="lblEmail"
 Text="Email Address:"
 AssociatedControlID="txtEmail"
 Runat="server" />
 <br />
 <asp:TextBox
 id="txtEmail"
 Runat="server" />
 <asp:RegularExpressionValidator
 id="regEmail"
 ControlToValidate="txtEmail"
 Text="(Invalid email)"
 ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
 Runat="server" /> 

 <br /><br />

 <asp:Label
 id="lblHours"
 text="Hours Worked"
 runat="server" />
 <br />
 <asp:TextBox
 id="txtHours"
 Runat="server"
 width="40" />
 <asp:RangeValidator
 id="RangeValidator1"
 ControlToValidate="txtHours"
 Text="Enter a valid number of hours (must be between 10 and 60)"
 MinimumValue="10"
 MaximumValue="60"
 Runat="server" />

 <br /><br />

 <asp:Label 
 ID="lblStartDate"
 Text="Start Date:"
 Runat="server" />
 <asp:TextBox
 id="txtStartDate"
 Runat="server" />

 <br /><br /> 

 <asp:Label 
 id="lblEndDate"
 Text="End Date:"
 Runat="server" />
 <asp:TextBox
 id="txtEndDate"
 Runat="server" />
 <asp:CompareValidator
 id="cmpDate"
 Text="(End date must be greater than start date)"
 ControlToValidate="txtEndDate"
 ControlToCompare="txtStartDate"
 Type="Date"
 Operator="GreaterThan"
 Runat="server" />

<br /><br />



 <asp:Button
 ID="btnSubmit"
 Text="Submit"
 Runat="server" />


</div>
</form>
</body>
</html>
1

There are 1 answers

1
Jose M. On BEST ANSWER

You need set the ErrorMessage in your validators like this:

 <asp:RequiredFieldValidator ErrorMessage="Fist name is required" ...