473,396 Members | 2,013 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,396 software developers and data experts.

customValidator doesn't work

Hello,

I have some code as follows.
It seems that customValidator doesn't work - because i don't get any
message.

In the body :
<asp:table>

<asp:TableRow>
<asp:TableCell>
<asp:RequiredFieldValidator
ControlToValidate="a_email"
Text="*"
runat="server" />
</asp:TableCell>
<asp:TableCell>email:</asp:TableCell>
<asp:TableCell><asp:TextBox id="a_email" runat="server"
/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="Illegal"
ErrorMessage="Illegal"
runat="server" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>
....

In the script :

<script runat = "server">
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false 'just testing - always false, but even this doesn't
work.
End sub
</script>
....

What is wrong in my code ?

Thanks :)
Nov 18 '05 #1
10 4734
Could be you're using <asp:Table>, which is server side, not client side.
Change it to a standard HTML <table> and the validator should work.
"Mr. x" <a@b.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have some code as follows.
It seems that customValidator doesn't work - because i don't get any
message.

In the body :
<asp:table>

<asp:TableRow>
<asp:TableCell>
<asp:RequiredFieldValidator
ControlToValidate="a_email"
Text="*"
runat="server" />
</asp:TableCell>
<asp:TableCell>email:</asp:TableCell>
<asp:TableCell><asp:TextBox id="a_email" runat="server"
/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="Illegal"
ErrorMessage="Illegal"
runat="server" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>
...

In the script :

<script runat = "server">
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false 'just testing - always false, but even this doesn't
work.
End sub
</script>
...

What is wrong in my code ?

Thanks :)

Nov 18 '05 #2
Your codes shows that you are using a RequiredFieldValidator not a
CustomValidator as this post's subject implies. Which is it?
"Mr. x" <a@b.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have some code as follows.
It seems that customValidator doesn't work - because i don't get any
message.

In the body :
<asp:table>

<asp:TableRow>
<asp:TableCell>
<asp:RequiredFieldValidator
ControlToValidate="a_email"
Text="*"
runat="server" />
</asp:TableCell>
<asp:TableCell>email:</asp:TableCell>
<asp:TableCell><asp:TextBox id="a_email" runat="server"
/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="Illegal"
ErrorMessage="Illegal"
runat="server" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>
...

In the script :

<script runat = "server">
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false 'just testing - always false, but even this doesn't
work.
End sub
</script>
...

What is wrong in my code ?

Thanks :)

Nov 18 '05 #3
There is one of each... He must've figured it out as he hasn't replied to
either post.
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Your codes shows that you are using a RequiredFieldValidator not a
CustomValidator as this post's subject implies. Which is it?
"Mr. x" <a@b.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Hello,

I have some code as follows.
It seems that customValidator doesn't work - because i don't get any
message.

In the body :
<asp:table>

<asp:TableRow>
<asp:TableCell>
<asp:RequiredFieldValidator
ControlToValidate="a_email"
Text="*"
runat="server" />
</asp:TableCell>
<asp:TableCell>email:</asp:TableCell>
<asp:TableCell><asp:TextBox id="a_email" runat="server"
/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="Illegal"
ErrorMessage="Illegal"
runat="server" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>
...

In the script :

<script runat = "server">
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false 'just testing - always false, but even this doesn't
work.
End sub
</script>
...

What is wrong in my code ?

Thanks :)


Nov 18 '05 #4
> There is one of each... He must've figured it out as he hasn't replied to
either post.

Well,
It's good somebody notice that I have both RequiredFieldValidator and
CustomValidator.
(I have checked also without RequiredFieldValidator - the same result).

Still, I didn't resolve the problem, and I am still waiting for kind a
solution, please.

Thanks :)
Nov 18 '05 #5
Mr. x wrote:
There is one of each... He must've figured it out as he hasn't replied to
either post.


Well,
It's good somebody notice that I have both RequiredFieldValidator and
CustomValidator.
(I have checked also without RequiredFieldValidator - the same result).

Still, I didn't resolve the problem, and I am still waiting for kind a
solution, please.


Your code as originally posted seems to work fine for me - I did have to
add a few overhead-type tags to get ASP.NET to accept the file (@Page,
the form tag, etc.), but otherwise I simply pasted in what you posted.

Here's exactly what I placed into an IIS application directory in test.aspx:
================================================== =====================
<%@ Page language="VB" debug="false" %>

<html>
<head>
</head>
<body>
<form runat="server">
<asp:table>

<asp:TableRow>
<asp:TableCell>
<asp:RequiredFieldValidator
ControlToValidate="a_email"
Text="*"
runat="server" />
</asp:TableCell>
<asp:TableCell>email:</asp:TableCell>
<asp:TableCell><asp:TextBox id="a_email" runat="server"
/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="Illegal"
ErrorMessage="Illegal"
runat="server" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>

<script runat = "server">
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false 'just testing - always false
End sub
</script>

</form>
</body>
</html>
================================================== =====================

If you still have the problem with this exact aspx file, you might want
to run a repair installation for your .NET Framework.

--
mikeb
Nov 18 '05 #6
Mr. x wrote:
Look at the attachment file, and see that customValidator doesn't work - why
?
You need to test for the validity of the page in your
sendContactMessage() button click handler.

Put the following lines at the top of sendContactMessage():

If Not Me.IsValid Then
Return
End If

and I think you'll get the behavior you want.
For details, see:
http://msdn.microsoft.com/library/en...mmatically.asp


(Also - it's for .net, and I don't know whether it is bug on .net or not,
but when I validate this file on :
http://validator.w3.org, it seems to be wrong, because of .net).

Thanks :)

"mikeb" <ma************@mailnull.com> wrote in message
news:ON*************@tk2msftngp13.phx.gbl...
Mr. x wrote:

There is one of each... He must've figured it out as he hasn't replied
to
either post.

Well,
It's good somebody notice that I have both RequiredFieldValidator and
CustomValidator.
(I have checked also without RequiredFieldValidator - the same result).

Still, I didn't resolve the problem, and I am still waiting for kind a
solution, please.


Your code as originally posted seems to work fine for me - I did have to
add a few overhead-type tags to get ASP.NET to accept the file (@Page,
the form tag, etc.), but otherwise I simply pasted in what you posted.

Here's exactly what I placed into an IIS application directory in


test.aspx:
================================================ =======================
<%@ Page language="VB" debug="false" %>

<html>
<head>
</head>
<body>
<form runat="server">
<asp:table>

<asp:TableRow>
<asp:TableCell>
<asp:RequiredFieldValidator
ControlToValidate="a_email"
Text="*"
runat="server" />
</asp:TableCell>
<asp:TableCell>email:</asp:TableCell>
<asp:TableCell><asp:TextBox id="a_email" runat="server"
/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="Illegal"
ErrorMessage="Illegal"
runat="server" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>

<script runat = "server">
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false 'just testing - always false
End sub
</script>

</form>
</body>
</html>
================================================ =======================

If you still have the problem with this exact aspx file, you might want
to run a repair installation for your .NET Framework.

--
mikeb


--
mikeb
Nov 18 '05 #7
"mikeb" <ma************@mailnull.com> wrote in message
news:Od**************@tk2msftngp13.phx.gbl...
Mr. x wrote:
Hello,
I am Eitan, and I use sometimes Mr. X as nick-name in newsgroups.
Look at the attachment file, and see that customValidator doesn't work - why ?


You need to test for the validity of the page in your
sendContactMessage() button click handler.

Put the following lines at the top of sendContactMessage():

If Not Me.IsValid Then
Return
End If

and I think you'll get the behavior you want.


I did as you said If Not Me.IsValid Then
Return
End If

)
and now it's almost O.K.
When everythiing is typed correctly I get no message - that's OK.

When the e-mail is typed wrong,
I get the message of ValidationSummary :
Fields with astarisks are must.

I don't want to get this message in every case my input is wrong.
How can I do that ?

Look at my code for :
<asp:ValidationSummary
HeaderText="Fields with astarisks are must"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>

Thanks :)
Nov 18 '05 #8
Eitan wrote:
"mikeb" <ma************@mailnull.com> wrote in message
news:Od**************@tk2msftngp13.phx.gbl...
Mr. x wrote:

Hello,
I am Eitan, and I use sometimes Mr. X as nick-name in newsgroups.

Look at the attachment file, and see that customValidator doesn't work -
why
?


You need to test for the validity of the page in your
sendContactMessage() button click handler.

Put the following lines at the top of sendContactMessage():

If Not Me.IsValid Then
Return
End If

and I think you'll get the behavior you want.

I did as you said
If Not Me.IsValid Then
Return
End If


)
and now it's almost O.K.
When everythiing is typed correctly I get no message - that's OK.

When the e-mail is typed wrong,
I get the message of ValidationSummary :
Fields with astarisks are must.

I don't want to get this message in every case my input is wrong.
How can I do that ?

Look at my code for :
<asp:ValidationSummary
HeaderText="Fields with astarisks are must"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>

Thanks :)


Well, the HeaderText property of the ValidationSummary control is just
that - a header that's displayed whenever the validation summary is
displayed. You should set it to a more generic message, or you could
dynamically set it in a Page_Load handler that examines all the
validation controls in the Page.Validators collection and see which ones
failed to create an appropriate message.

But it would probably be simpler to have HeaderText be a generic header,
and set the ErrorMessage and Text properties for the various validators
so that appropriate messages are displayed in the appropriate locations.

--
mikeb
Nov 18 '05 #9
"mikeb" <ma************@mailnull.com> wrote in message
Well, the HeaderText property of the ValidationSummary control is just
that - a header that's displayed whenever the validation summary is
displayed. You should set it to a more generic message, or you could
dynamically set it in a Page_Load handler that examines all the
validation controls in the Page.Validators collection and see which ones
failed to create an appropriate message. Can you give me some examples of page_load, please ?
But it would probably be simpler to have HeaderText be a generic header,
and set the ErrorMessage and Text properties for the various validators
so that appropriate messages are displayed in the appropriate locations.


I'll check this out, but ...
What generic, i.e ?
Is "There was an error on the following fields" good enough ?
Are there any examples for that ?

What if I several fields that are required fields - for them I want one
generic message.
and two fields that are not required, but not written correctly
(CustomValidator return false) - for them I want each one to have one
message at summary.
How can I do that ?

Thanks :)
Nov 18 '05 #10
N.B.
Another thing, is when I do customValidator, I see that there is not even a
single message for customValidator.
What I did :
<asp:TableRow>
<asp:TableCell ColumnSpan = "3">
<asp:CustomValidator
ControlToValidate="a_email"
OnServerValidate="checkEmail"
Text="my text"
ErrorMessage="my message"
runat="server" />
</asp:TableCell>
</asp:TableRow>

and in the function
checkEmail(source As object,args As ServerValidateEventArgs)
Sub checkEmail(source As object,args As ServerValidateEventArgs)
args.IsValid=false
End Sub
....
and in the eror summary I don't get a message for email - Why ?

Thanks :)
Nov 18 '05 #11

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

Similar topics

5
by: Gene McCrory | last post by:
Is it possible to have a CustomValidator against two controls in an EditItemTemplate on a DataGrid? Case: Have a business rule that states if ATextBox starts with "ACertainValue" then BTextBox...
3
by: Ronan Dodworth | last post by:
Hi there I'm having a little bit of a problem with my customvalidator control. The problem is the javascript runs fine on my local webserver IIS but not when I post it to the web hosting server....
1
by: SMG | last post by:
Hi All. My forms has two textboxes, 1 username, 2 password. Both has requiredfield validator it works fine when there is no input in these textboxes. And the errorMsg is shown in...
1
by: Vi | last post by:
Hi, I have two pairs of a DropDownList and TextBox Controls and for each pair I have a CustomValidator that makes sure that at least one of the two (DropDownList or TextList) has a value. When I...
1
by: Ricky Williams | last post by:
I have a CustomValidator for a Radio Button that works fine with IE, but doesn't trigger with Firefox or Netscape. I have been stuck on this one for 3 weeks; any suggestions greatly appreciated....
1
by: Beffmans | last post by:
Hi I have defined an customvalidator on my TextBox: function clientvalidate(source, arguments){ { // even number? if (arguments.Value%2 == 0) arguments.IsValid = true; else
1
by: RTT | last post by:
It's my first time i want to write a cotum validator but it doesn't seem to work. In de page i've put this validator: <asp:CustomValidator id="CVFBeginDate"...
1
by: Jason Chan | last post by:
wroten following aspx in VWD 2005 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
3
by: Stan SR | last post by:
Hi, I have a web user control that contains 3 dropdownlists it's a date selector, so one contains the days, one the months and the last the years. Each of them starts with a blank value. I...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.