CustomValidator on CheckBox not working

T

theresa

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
 
B

bruce barker

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)

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
 
T

theresa

Hi Bruce -

Thanks for your reply! I didn't supply a client function because I was
trying to use server-side validation. However, as soon as I added a
client validation function, the server-side validator started working!
Odd, and I'm thinking perhaps Microsoft should have mentioned that in
their documentation somewhere. Anyway, thanks for your help! I'm so
glad to have this finally resolved.

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)
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"
'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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top