CustomValidator always returns invalid?

  • Thread starter Thread starter Andy B.
  • Start date Start date
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?
 
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Back
Top