472,358 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 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 4676
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.