views:

445

answers:

3

I'm trying to figure out how the heck the validation summary control of ASP.NET (3.5 I think) works.

<asp:ValidationSummary ID="vldSummary" runat="server" DisplayMode="BulletList" 
  CssClass="error" EnableClientScript="true" />
<asp:RequiredFieldValidator ID="vldSubject" ControlToValidate="txtSubject"
  EnableClientScript="false" Text="You must enter a subject." runat="server" />
<asp:RequiredFieldValidator ID="vldMessage" ControlToValidate="txtMessage"
  EnableClientScript="false" runat="server" Text="You must enter a message." />

It seems that no matter what I do, the validation summary remains empty (but is rendered) and the errors are only displayed at the position of each respective validator.

What am I doing wrong?

+2  A: 

You want to set the ErrorMessage property on your validation controls. This text will be displayed by the ValidationSummary control.

Try:

<asp:ValidationSummary ID="vldSummary" runat="server" DisplayMode="BulletList" CssClass="error" EnableClientScript="true" />
<asp:RequiredFieldValidator ID="vldSubject" ControlToValidate="txtSubject" EnableClientScript="false" ErrorMessage="You must enter a subject." runat="server" />
<asp:RequiredFieldValidator ID="vldMessage" ControlToValidate="txtMessage" EnableClientScript="false" runat="server" ErrorMessage="You must enter a message." />
dariom
+2  A: 

Text property's value is what is displayed beside the control. You need to set the ErrorMessage property of the validators to control what is shown in the summary.

Mitchel Sellers
+1  A: 

Set the ErrorMessage property on the RequiredFieldValidators, not the Text property.

<asp:RequiredFieldValidator ID="vldSubject" ControlToValidate="txtSubject" EnableClientScript="false" ErrorMessage="You must enter a subject." runat="server" />
<asp:RequiredFieldValidator ID="vldMessage" ControlToValidate="txtMessage"  EnableClientScript="false" runat="server" ErrorMessage="You must enter a message." />
Jason Berkan