验证控件的消息单条弹出
今天客户提出不希望如我们过去显示验证控件错误消息所用发summary方式,希望每次只显示一条。本来最好的方法应该是修改js了,奈何太麻烦,就用后台校验吧。
Public Shared Function ServerCheck(ByVal objValiPage As Page) As Boolean
Dim lst As System.Collections.Generic.List(Of System.Web.UI.Control) = New System.Collections.Generic.List(Of System.Web.UI.Control)()
Dim arrCtr() As System.Web.UI.Control = CheckControls(lst, objValiPage.Controls)
For Each valiCtrl As BaseValidator In arrCtr
valiCtrl.Validate()
If Not valiCtrl.IsValid() Then
JSCommon.Alert(objValiPage, valiCtrl.ErrorMessage)
Return False
End If
Next
Return True
End Function
Private Shared Function CheckControls(ByVal lstCtl As System.Collections.Generic.List(Of System.Web.UI.Control), ByVal arrCobtrol As System.Web.UI.ControlCollection) As System.Web.UI.Control()
For Each ctrl As System.Web.UI.Control In arrCobtrol
If Not TypeOf ctrl Is BaseValidator Then
If ctrl.Controls.Count > 0 Then
CheckControls(lstCtl, ctrl.Controls)
End If
Else
lstCtl.Add(ctrl)
End If
Next
Return lstCtl.ToArray()
End Function
Dim lst As System.Collections.Generic.List(Of System.Web.UI.Control) = New System.Collections.Generic.List(Of System.Web.UI.Control)()
Dim arrCtr() As System.Web.UI.Control = CheckControls(lst, objValiPage.Controls)
For Each valiCtrl As BaseValidator In arrCtr
valiCtrl.Validate()
If Not valiCtrl.IsValid() Then
JSCommon.Alert(objValiPage, valiCtrl.ErrorMessage)
Return False
End If
Next
Return True
End Function
Private Shared Function CheckControls(ByVal lstCtl As System.Collections.Generic.List(Of System.Web.UI.Control), ByVal arrCobtrol As System.Web.UI.ControlCollection) As System.Web.UI.Control()
For Each ctrl As System.Web.UI.Control In arrCobtrol
If Not TypeOf ctrl Is BaseValidator Then
If ctrl.Controls.Count > 0 Then
CheckControls(lstCtl, ctrl.Controls)
End If
Else
lstCtl.Add(ctrl)
End If
Next
Return lstCtl.ToArray()
End Function