473,387 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Custom validator not preventing processing

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
Aug 1 '08 #1
1 3866
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" <st***********@gmail.comwrote in message
news:47**********************************@l64g2000 hse.googlegroups.com...
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

Aug 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike P | last post by:
I have a Custom validator that has ControlToValidate set to a textbox that also has a Required and RegularExpression validator. When I run the webpage on my machine the custom validator...
2
by: Evgueni | last post by:
Hello, I am new to .NET, and a custom validator is giving me a lot of grief. I want to use a Custom Validation control and for some reasons it's not firing the validation procedure. I am using...
1
by: DotNetGruven | last post by:
Can I create a custom validator control in my project and add it to a PlaceHolder on my ASPX page?? Here is what I've tried. It compiles and runs without error, but doesn't detected that the...
2
by: Dot net work | last post by:
Hello. If I use an asp.net custom validator control to validate a textbox, what I find is that if I enter in some text that I have already entered and validated in a previous session (you know...
5
by: Richard Payne | last post by:
Hi This is probably a newbie question but I can't seem to find a clear answer to the problem I have. I have created a Custom Validator control on my webform that works fine, but when I put...
9
by: Alex Shirley | last post by:
Hi there I’m simply trying to check for a blank or empty value in a textbox on my webform. In this instance I do not want to use a requiredfieldvalidator, I want to use a customvalidator (as I...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
2
by: Alan Silver | last post by:
Hello, I have a custom validator on my page, and have the server-side code working fine. I want to add a client-side funtion as well, but am not sure how to wire it in so that it works with the...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
1
gagandeepgupta16
by: gagandeepgupta16 | last post by:
Hi I am working on an entry form using validation controls in ASP.NET. I have two controls which requires custom validators, no issue in using plain custom validators. But when i am using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.