473,413 Members | 1,833 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,413 software developers and data experts.

ASP.NET CustomValidation Won't be fired.

Hi, guys

I have asp.net form contain several textbox controls and one field is
userName I want to validate this field to make sure there is no other
user have the same userName before saving. so I create a
customValidator to do that. The strange thing is that customValidator
never fired the validation event.

Here is the code:
in aspx file the control is:
<DIV><SPAN class="form_label">Username</SPAN>
<SPAN class="form_field">
<asp:TextBox id="userName" Runat="server"
CssClass="NormalTextBox" MaxLength="25"></asp:TextBox>
<asp:RequiredFieldValidator id="userNameRequiredfieldvalidator"
Runat="server" Display="Static" ErrorMessage="User Name is Required
Field."
ControlToValidate="userName"
NAME="userNameRequiredfieldvalidator"></asp:RequiredFieldValidator>
<asp:CustomValidator id="userNameCustomValidator" runat="server"
Display="static" ErrorMessage="error"></asp:CustomValidator>
</SPAN></DIV>

in aspx.cs file:
private void InitializeComponent(){
this.userNameCustomValidator.ServerValidate += new
System.Web.UI.WebControls.ServerValidateEventHandl er(this.userNameCustomValidator_ServerValidate);
}

private void userNameCustomValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = false;
}

I set a breakpoint inside the validation funtion, but seem like the
application never go through the function.

I could not figure out what the problem is. Please help. Thanks!

Nov 19 '05 #1
1 1241
If the textbox is blank, the CustomValidator will not fire. (That's why you
have a RequiredFieldValidator.)

Make sure that Page.Validate() is being called. It is automatically called
by your submit button's OnClick method just prior to calling its Click
event, unless you have CausesValidation=false.

It doesn't hurt to test things by calling userNameCustomValidator.Validate()
inside your Click event method. If it works there, it tells you that
Page.Validate() isn't called.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

<zl****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi, guys

I have asp.net form contain several textbox controls and one field is
userName I want to validate this field to make sure there is no other
user have the same userName before saving. so I create a
customValidator to do that. The strange thing is that customValidator
never fired the validation event.

Here is the code:
in aspx file the control is:
<DIV><SPAN class="form_label">Username</SPAN>
<SPAN class="form_field">
<asp:TextBox id="userName" Runat="server"
CssClass="NormalTextBox" MaxLength="25"></asp:TextBox>
<asp:RequiredFieldValidator id="userNameRequiredfieldvalidator"
Runat="server" Display="Static" ErrorMessage="User Name is Required
Field."
ControlToValidate="userName"
NAME="userNameRequiredfieldvalidator"></asp:RequiredFieldValidator>
<asp:CustomValidator id="userNameCustomValidator" runat="server"
Display="static" ErrorMessage="error"></asp:CustomValidator>
</SPAN></DIV>

in aspx.cs file:
private void InitializeComponent(){
this.userNameCustomValidator.ServerValidate += new
System.Web.UI.WebControls.ServerValidateEventHandl er(this.userNameCustomValidator_ServerValidate);
}

private void userNameCustomValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = false;
}

I set a breakpoint inside the validation funtion, but seem like the
application never go through the function.

I could not figure out what the problem is. Please help. Thanks!

Nov 19 '05 #2

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

Similar topics

2
by: rodchar | last post by:
hey all, I'm not sure if this is even possible but here goes: if i put a CustomValidator control in my EditItem template column how do i get to it? Or how and where do i write my custom code for...
2
by: kpg | last post by:
Hi all, This should be simple... I have a TextBox1 and a customvalidation control linked to it. I use a client side script to validate the textbox. If the data is not valid I want to return...
5
by: gane kol | last post by:
Hi I have a set of Yes/No radio buttons with textboxes for each. I need to write a common customvalidation function that checks, if radiobutton "yes" is selected, the value in the corresponding...
1
by: SAI | last post by:
Should I bind one of the controls to the CustomValidation Object? e.g. bind text box to it. In some cases, I may need to check 2 web object contents. How to do it in one CustomValidation Object? ...
2
by: Ryan Liu | last post by:
Hi, I need the MouseDown event be trigged everytime when you press mouse in a datagrid (System.Windows.Forms). But seems mouse event will only fire once, and it seems changed to edit mode...
6
by: Adam Honek | last post by:
Okay. This is a little strange but here goes. I wanted to send emails and hence wrote the first sub below. It worked however it would NOT send the email UNLESS I closed the application (hence...
18
by: Rainer Queck | last post by:
Hello NG, I realized, that my application won't start, if a referenced assembly is missing. Basically this is understandable, but since I destribute my applictaion without a setup, it can...
1
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
I have a drop down list in my asp page. when I selectg an irem and click on a button it appears in the Grid view. But when I again come to the same page and click on the same item from Drop down...
1
by: Craig Buchanan | last post by:
I have a Web User Control (.ascx file) that I need to valid using a CustomValidation control. Moreover, I would like use client and server validation, if possible. I have the logic for the...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.