views:

21

answers:

2

Hi All,

I want to use Validation Controls but I dont want them to show their Error Messages when invalid data exist. Instead I'm going to iterate through the validation controls and show error messages inside my little ErrorMessage Control

for (int i = 0; i < Page.Validators.Count; i++)
        {
            if (!Page.Validators[i].IsValid)
            {
                divAlert.InnerText = Page.Validators[i].ErrorMessage;
                return false;
            }                
        }

I'm doing this because i have little space to show the error message. You can ask why are you using validation control if you dont want to show them My asnwer is "I use them for validation logic they handle"

I looked the properties of the validation controls and cant find something that wil help me doing this.

Any Idea?

Thanks

+2  A: 

Set the Display attribute on your validators to None.

Like:-

<asp:RegularExpressionValidator ID="MyValidator" runat="server" Display="None" />
Paul Alan Taylor
thanks i guess i need glasses =)
mehmet6parmak
+2  A: 

You may want to checkout the ValidationSummary Control which is built for this, take a look at a quick demo here.

For example this shows just a red asterisk at the field, but a full field name in the summary:

 <asp:RequiredFieldValidator ControlToValidate="myControl" runat="server"
  ErrorMessage="Summary Description" Text="*" InitialValue="" />
 <asp:ValidationSummary runat="server"
  HeaderText="You must enter a value in the following fields:"
  DisplayMode="BulletList" EnableClientScript="true" />
Nick Craver