467,122 Members | 1,257 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,122 developers. It's quick & easy.

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
  • viewed: 4529
Share:
10 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Vi | last post: by
1 post views Thread by Ricky Williams | last post: by
1 post views Thread by Beffmans | last post: by
1 post views Thread by RTT | last post: by
1 post views Thread by Jason Chan | last post: by
3 posts views Thread by Stan SR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.