theres an "Object reference not set to an instance of an object." error in my

spidy_kane

New member
asp.net 2.0 code can any one fix? Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
For Each ValControl As BaseValidator In Page.Validators
Dim assControl As WebControl
assControl = Page.FindControl(ValControl.ControlToValidate)
If Not ValControl.IsValid Then
assControl.BackColor = Drawing.Color.Yellow
Else
assControl.BackColor = Drawing.Color.White
End If
Next

End Sub
 
"assControl = Page.FindControl(ValControl.ControlToVal…
If Not ValControl.IsValid Then
assControl.BackColor = Drawing.Color.Yellow
Else
assControl.BackColor = Drawing.Color.White
End If"

There's no guarantee that Page.FindControl is actually finding a valid control to put into the assControl reference.

It probably isn't, hence a NullReferenceException
 
"assControl = Page.FindControl(ValControl.ControlToVal…
If Not ValControl.IsValid Then
assControl.BackColor = Drawing.Color.Yellow
Else
assControl.BackColor = Drawing.Color.White
End If"

There's no guarantee that Page.FindControl is actually finding a valid control to put into the assControl reference.

It probably isn't, hence a NullReferenceException
 
Back
Top