我真的不知道为什么会这样。验证摘要似乎是非常基本的控件。点击"提交"按钮,各个错误消息显示为字段(例如,当需要字段时,错误消息说"字段必需"出现在文本框旁边),但没有任何内容出现在我的验证摘要应该是。我没有任何验证组,因为我想验证页面上的所有内容。我页面上的所有内容看起来都很好。我似乎无法弄清楚可能阻止摘要显示的内容。验证摘要位于页面顶部。这是我的代码:
<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>
答案 0 :(得分:2)
您需要在验证器中设置错误消息,如下所示:
<asp:RequiredFieldValidator ErrorMessage="Fist name is required" ...