469,898 Members | 2,033 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

CustomValidator on CheckBox not working

I'm about at my wits end trying to figure out why this isn't working,
so I'm hoping one of you can help! I'm sure there must be something
simple I'm missing.

I have a checkbox on an Asp.NET 2.0 web form that needs to be checked
before the form is successfully submitted. I've done the same thing on
an Asp.NET 1.1 form before and had no problems, but using the exact
same code on the 2.0 form absolutely nothing happens. No errors of any
kind (not even Javascript) and it acts the same in both Firefox and
IE. I've tried adding various test statements to the server-side
validation function (as indicated in the commented out code below),
but even those don't appear. I should add that all of the
RequiredFieldValidators on the page work just fine. Code below. Any
help is most appreciated!

<asp:CheckBox ID="chkStatement" runat="server" TextAlign="right" />

<asp:CustomValidator runat="server" id="custStatement"
OnServerValidate="reqStatement" ErrorMessage="* You must check the
checkbox."
Font-Bold="true" Font-Size="15" ForeColor="#FF0000" Display="dynamic"
! </asp:CustomValidator>
'require the statement be checked before submission
Sub reqStatement(sender as Object, args as ServerValidateEventArgs)

args.IsValid = chkStatement.Checked
'response.write("reqStatement fired") [does nothing]
'args.IsValid = False [also does nothing]

End Sub

Sep 12 '07 #1
1 5791
you did not supply a client function, so no javascript is generated.
does you server code call Page.IsValid or Page.Validate(), so that
server validation is run?
-- bruce (sqlwork.com)
theresa wrote:
I'm about at my wits end trying to figure out why this isn't working,
so I'm hoping one of you can help! I'm sure there must be something
simple I'm missing.

I have a checkbox on an Asp.NET 2.0 web form that needs to be checked
before the form is successfully submitted. I've done the same thing on
an Asp.NET 1.1 form before and had no problems, but using the exact
same code on the 2.0 form absolutely nothing happens. No errors of any
kind (not even Javascript) and it acts the same in both Firefox and
IE. I've tried adding various test statements to the server-side
validation function (as indicated in the commented out code below),
but even those don't appear. I should add that all of the
RequiredFieldValidators on the page work just fine. Code below. Any
help is most appreciated!

<asp:CheckBox ID="chkStatement" runat="server" TextAlign="right" />

<asp:CustomValidator runat="server" id="custStatement"
OnServerValidate="reqStatement" ErrorMessage="* You must check the
checkbox."
Font-Bold="true" Font-Size="15" ForeColor="#FF0000" Display="dynamic"
>! </asp:CustomValidator>

'require the statement be checked before submission
Sub reqStatement(sender as Object, args as ServerValidateEventArgs)

args.IsValid = chkStatement.Checked
'response.write("reqStatement fired") [does nothing]
'args.IsValid = False [also does nothing]

End Sub
Sep 12 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stephen Miller | last post: by
1 post views Thread by Nathan Sokalski | last post: by
3 posts views Thread by Jaime Stuardo | last post: by
reply views Thread by RichardH | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.