2010-01-31 35 views

回答

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 
+0

編碼的任何例子嗎? – kennedy 2010-01-31 09:41:57

+0

我已經添加了一些示例代碼 – 2010-01-31 15:24:19

相關問題