当我的验证失败超过3次时,我如何编码,用户将指向另一页?
答案 0 :(得分:1)
我使用CustomValidator来执行验证。在CustomValidator的代码中,我将使用ViewState变量来跟踪验证失败的次数以及变量> 3然后我会使用Response.Redirect()转到另一页。
以下是一些示例代码:
Property ValidationFailed() As Integer
Get
If ViewState("ValidationFailed") Is Nothing Then
Return 0
Else
Return ViewState("ValidationFailed")
End If
End Get
Set(ByVal value As Integer)
ViewState("ValidationFailed") = value
End Set
End Property
Public Function ValidationCode(ByVal arg As Object) As Boolean
'TODO: Code that does the validation
End Function
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
args.IsValid = ValidationCode(args.Value)
If Not args.IsValid Then
ValidationFailed = ValidationFailed + 1
End If
If ValidationFailed > 3 Then
Response.Redirect("somepage.aspx")
End If
End Sub