Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is "Page.IsValid = True' even when "args.IsValid = False"?

Status
Not open for further replies.

langoo

Programmer
Jun 22, 2008
8
IL
Hi Folks,

I'm getting strange behavior with custom validation controls -
They all stopped working!
The Validation Controls do their job...by making args.isValid to False..
but for some reason Page.isValid remains always true...so in fact it is as though the validators had no effect on the page...

What can be causing this?

This is an example of a validator I have on the page with the resulting trace out:
Validation Event:

Protected Sub CustomValEClaim_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
' Trace that event is firring
Trace.Warn("CustomVal Happening")
' Trace Values which Validator must compare
Trace.Warn("Max " + Session("MaxVal").ToString)
Trace.Warn("Current " + CurrentVal.Text)

' Evaluate True or False
If CInt(CurrentVal.Text) < Session("MaxVal") Then
args.IsValid = True
'
Trace.Warn("Args Should be True")
Trace.Warn("args.isValid:" + args.IsValid.ToString)
Trace.Warn("page.isValid: " + Page.IsValid.ToString)
Else
args.IsValid = False
args.IsValid = False
Trace.Warn("Should be False")
Trace.Warn("args.isValid:" + args.IsValid.ToString)
Trace.Warn("page.isValid: " + Page.IsValid.ToString)
End If

End Sub

TraceOut

CustomVal Happening
Max 10
Current 12
Should be False
args.isValid:False
page.isValid: True < --- Why is this True..when args.isValid is False?!



Regards,

- Joel
 
you can simplify your code significatly, simply by doing this
Code:
//trace statements
args.IsValid = CInt(CurrentVal.Text) < Session("MaxVal")
//trace statements
no need for the if/else

I would check to make sure
1. the handler is wired to the event (either in code behind or markup)
2. the validator being called exactly 1 time.
3. the location of where you check page.isvalid.

for #3 this would happen in a controls events handler (button, dropdown, gridview command, textchanged). it cannot happen in the init or load event because the page is alway valid at that point; the validation event has not fired.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top