© 2004 Microsoft Corporation. All rights reserved.

Figure 3 Custom Control
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace NoFormValControls

  Public Class NoFormValButton

  Inherits System.Web.UI.WebControls.Button

  Property [NoFormValList]() As String

    Get
       Dim o As Object = ViewState("NoFormValList")

       If o Is Nothing Then 
        Return String.Empty
      Else
        Return o.ToString
      End If
    End Get

    Set
      ViewState("NoFormValList") = Value
    End Set
  End Property

  Protected Overrides Sub Render(ByVal output As _
     System.Web.UI.HtmlTextWriter)

    Dim theRequest As System.Web.HttpRequest = _
       System.Web.HttpContext.Current.Request

    If [NoFormValList] <> "" Then
      If (theRequest.Browser.Browser.ToString = "IE") And _
         (CInt(theRequest.Browser.MajorVersion) >= 4) Then
        Dim intLoop As Integer
        Dim astrList() As String
        Dim strControl As String

        output.Writeline()
        output.Writeline("<script language=javascript>")
        output.Writeline("<!--")
        output.Writeline("function TurnOffVal" & MyBase.ID & "()")
        output.Writeline(chr(9) & "{")
        astrList = Split([NoFormValList], ",")
        For intLoop = 0 To astrList.GetUpperBound(0)
          strControl = astrList(intLoop).ToString
          output.WriteLine(chr(9) & "ValidatorEnable(" & strControl &
             ", false);")
        Next
        output.Writeline(chr(9) & "}")
        output.Writeline("//-->")
        output.Writeline("</script>")
        output.AddAttribute("onServerClick", MyBase.ID & "_Click")
  
        output.AddAttribute("onClick", "javascript:TurnOffVal" & MyBase.Id _
           & "(); if typeof(Page_ClientValidate) == 'function')" _ &
           "Page_ClientValidate();") 
      End If
    End If
    MyBase.CausesValidation = False
    MyBase.Render(output)
  End Sub

  Public Sub DisableServerSideValidation()
    Dim ctrlValidator As Control
    Dim intLoop As Integer
    Dim astrList() As String

    If [NoFormValList] <> "" Then
      astrList = Split([NoFormValList], ",")
      For intLoop = 0 To astrList.GetUpperBound(0)
        ctrlValidator = Page.FindControl(astrList(intLoop).ToString)
             If Not (ctrlValidator Is Nothing) Then  
          Select Case UCase(ctrlValidator.GetType.ToString)
            Case "SYSTEM.WEB.UI.WEBCONTROLS.REGULAREXPRESSIONVALIDATOR"
              CType(ctrlValidator, RegularExpressionValidator).IsValid
                 = True
            Case "SYSTEM.WEB.UI.WEBCONTROLS.REQUIREDFIELDVALIDATOR"
              CType(ctrlValidator, RequiredFieldValidator).IsValid = True
            Case "SYSTEM.WEB.UI.WEBCONTROLS.RANGEVALIDATOR"
              CType(ctrlValidator, RangeValidator).IsValid = True
            Case "SYSTEM.WEB.UI.WEBCONTROLS.COMPAREVALIDATOR"
              CType(ctrlValidator, CompareValidator).IsValid = True
            Case "SYSTEM.WEB.UI.WEBCONTROLS.CUSTOMVALIDATOR"
              CType(ctrlValidator, CustomValidator).IsValid = True
          End If
        End Select
      Next
    End If
  End Sub

  End Class

End Namespace
Figure 4 Save Changes
<script language=javascript>
<!--
function TurnOffValSave()
{
    ValidatorEnable(valReqTitle, false);
    ValidatorEnable(valREAdd, false);
    ValidatorEnable(valReqAdd, false);
}
//-->
</script>

<input onServerClick="Save_Click"
    onclick="javascript:TurnOffValSave();
    if (typeof(Page_ClientValidate) == 'function')
    Page_ClientValidate();" 
    type="submit" name="Save"
    value="Save Changes >>" id="Save" />