CustomValidator always returns invalid?

A

Andy B.

I have a GridView with 2 databound columns and a templateField with a
checkbox in its ItemTemplate. This gridview is inside step 1 of a wizard
control. What I need to do is when the next button is clicked, have the
CustomValidator check to see if there are any checkboxes in the
templateField column checked. If so, go to the next step. Otherwise
invalidate the page. Here is what I have for the server side event:

Protected Sub CheckBoxCustomValidator_ServerValidate(ByVal source As Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CheckBoxCustomValidator.ServerValidate

' Iterate through the NewsListGridView.Rows property

For Each row As GridViewRow In NewsListGridView.Rows

' Access the CheckBox

Dim cb = DirectCast(row.FindControl("SelectCheckBox"), CheckBox)

If cb.Checked = False Then

args.IsValid = False

End If

Next

End Sub

Problem is that it always makes the page invalid and unchecks all of the
checkboxes that wre checked before validation. Any way to fix this?
 
C

Cowboy \(Gregory A Beamer\)

I would put a breakpoint in each routine and see if you are accidentally
rebinding the CheckBoxList prior to the event handler being called. That
would do precisely what you are talking about here (all checkboxes
unchecked). And, if that is the case, it is very easy to fix with a branch
statement.

One common place to find the problem area is in the Page_Load event.
 
A

Andy B.

Where would i put the breakpoint?

Cowboy (Gregory A Beamer) said:
I would put a breakpoint in each routine and see if you are accidentally
rebinding the CheckBoxList prior to the event handler being called. That
would do precisely what you are talking about here (all checkboxes
unchecked). And, if that is the case, it is very easy to fix with a branch
statement.

One common place to find the problem area is in the Page_Load event.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top