Hi,
if validators update their IsValid correctly (so there's no problem), note
that you must check Page.IsValid in server-side code to prevent
validation-dependant logic from running. CustomValidators can prevent
client-side postbacl if client-sise validation is enabled but user can also
just disable js
See my post:
http://aspadvice.com/blogs/joteke/ar...hts_2900_.aspx
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Steveaux" <(E-Mail Removed)> wrote in message
news:479e32f6-5e71-4cb1-8367-(E-Mail Removed)...
> Hi, I'm new to ASP.Net, so this may be something simple that I
> forgot. I have a form where a person can create a login. I'm doing
> the processing on this myself. The form has a plethora of validators,
> including two custom validators. They check whether the user name
> exists among the users already registered, and the same with the email
> address. Both the validators process, but they don't stop the form
> from processing, so I end up with an error inserting a duplicate value
> into a unique field. Here's snippets of my code:
>
> <asp:CustomValidator ID="valUserNameExists" runat="server"
> OnServerValidate="CheckUserName"
> ErrorMessage="User Name already exists"
> ControlToValidate="txtUserName" ValidationGroup="RegisterForm">*</
> asp:CustomValidator>
> <asp:CustomValidator ID="valEmailAddressExists" runat="server"
> ControlToValidate="txtEmailAddress"
> OnServerValidate="CheckEmailAddress"
> ErrorMessage="Email Address already exists"
> ValidationGroup="RegisterForm">*</asp:CustomValidator>
>
> Code-behind:
>
> Creates a Sql query that returns the count of records with the user
> name or password, then:
> If objCommand.ExecuteScalar() > 0 Then
> args.IsValid = False
> lblValidate1.Text = "User Name exists."
> Else
> args.IsValid = True
> lblValidate1.Text = "User Name doesn't exist."
> End If
>
> lblValidate1 is just a temporary debugging label that I created. I
> commented out the Insert execution in the form processing so I could
> use this label to make sure the validators were working at all, and
> they were. Here's the button and the processing subroutine
> declaration:
>
> <input id="smtRegister" type="submit" value="Register" runat="server"
> causesvalidation="true" validationgroup="RegisterForm" />
>
> Public Sub smtRegister_ServerClick(ByVal sender As Object, ByVal e
> As System.EventArgs) Handles smtRegister.ServerClick