none
How to call Page.Validate() using javascript

    Question

  • Hi I need some help :)

    How to call Page.Validate() using javascript

    can anybody help me???

    Thursday, September 21, 2006 2:13 PM

All replies

  • Normally, for page.validate() to execute, the "causesvalidation" attribute must be set for asp.net controls that can automatically postback, and for the postback to occur.

    Since you want to trigger this via javascript, you will need to force a postback and pass a message back to the server telling it to execute page.validate().

    For example:

    Client code:

      <form id="Form1" method="post" runat="server">
        <script lang=javascript>
            function causeValidate() {
                document.Form1.hidDoValidate.value = "Y"; // Message to server-side code
                document.Form1.submit(); // Forces form to submit
            }
        </script>
        <input id="hidDoValidate" type="hidden" value="N" runat="server">
        <input id="btnDoValidate" type="button" value="Go" onclick="causeValidate();">
      </form>

    Server code:

        Protected WithEvents hidDoValidate As System.Web.UI.HtmlControls.HtmlInputHidden

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Page.IsPostBack Then
                If hidDoValidate.Value = "Y" Then
                    Page.Validate()
                End If
            End If
        End Sub

    That is an easy way. There are a million ways to implement this (not only my code), but hopefully it is obvious how this works.
    Just force the postback and using a hidden form variable, send a simple message to the server code to do the page.validate.
    In fact, you don't have to force the postback (unless you need to). You can let the postback happen like it normally would, but
    the hidden variable will signal the server code to execute the page.validate() method.

    Hope this helps.

    KenFitz

    Tuesday, September 26, 2006 6:45 PM
  • Hey ken Thanks  for ur kind !!!!

    But I also got one more solution for this situation.....

    we can actually call the asp.net validation script by calling Page_Validate() function in our javascript......

     

    Thanks !!!!

     

     

    Friday, February 16, 2007 11:41 AM
  • Hey ken Thanks  for ur kind help !!!!

    But I also got one more solution for this situation.....

    we can actually call the asp.net validation script by calling Page_Validate() function in our javascript......

     

    Thanks !!!!

     

     

    Friday, February 16, 2007 11:45 AM
  • Can you paste  the call to Page_Validate, when I called it in javascript, it says cannot find the Page_Validate
    Wednesday, March 14, 2007 2:35 PM
  •  

    It's name is Page_ClientValidate and I have read some code that you should check if it's a function using

    typeof(Page_ClientValidate) == 'function', i then used the return valud to see if it was valid or not.

    Wednesday, February 06, 2008 7:52 AM