开发者

ASP.NET validation controls

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;
            }  开发者_Go百科              
        }

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


Set the Display attribute on your validators to None.

Like:-

<asp:RegularExpressionValidator ID="MyValidator" runat="server" Display="None" />


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜