How to check from onclick if RequiredFieldValidator failed?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bogdan

    How to check from onclick if RequiredFieldValidator failed?

    Hi,

    I have a OnClientClick script assigned to a button. From the script, I'd
    like to check if RequiredFieldVa lidator attached to a textbox on the page
    has failed. The Page_IsValid works fine with - for example - regex
    validator but it does not work with the required field validator.

    Any suggestions will be appreciated.
    Thanks,
    Bogdan


  • =?Utf-8?B?TWFuaXNo?=

    #2
    RE: How to check from onclick if RequiredFieldVa lidator failed?

    Hi Bogdan,

    Please try the code below to check if page is valid or not in client side
    script.

    <head runat="server">
    <title>Untitl ed Page</title>
    <script type="text/javascript">
    function ConfirmSave()
    {
    if (Page_IsValid )
    {
    return confirm('want to continue?');
    }
    else
    {
    return false;
    }
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
    <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
    runat="server" ControlToValida te="TextBox1"

    ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
    <asp:Button ID="Button1" runat="server" Text="Button"
    OnClientClick=" return ConfirmSave();" UseSubmitBehavi or="False"/></div>
    </form>
    </body>

    Regards,
    Manish

    "Bogdan" wrote:
    Hi,
    >
    I have a OnClientClick script assigned to a button. From the script, I'd
    like to check if RequiredFieldVa lidator attached to a textbox on the page
    has failed. The Page_IsValid works fine with - for example - regex
    validator but it does not work with the required field validator.
    >
    Any suggestions will be appreciated.
    Thanks,
    Bogdan
    >
    >
    >

    Comment

    • Bogdan

      #3
      Re: How to check from onclick if RequiredFieldVa lidator failed?

      Manish,

      Thanks for the reply. Unfortunately this does not work for me. It actually
      illustrates the problem that I've been having - i.e. Page_IsValid is true
      even when the text box is empty. So, regardless of the content of the text
      box I always get the 'want to continue?' message box.

      Does this example behaves differently on your system? If yes, what browser
      and asp version do you use?
      I tested it in IE, FireFox, and Safari with asp 2.0 on the server.

      Thanks again,
      Bogdan

      "Manish" <Manish@discuss ions.microsoft. comwrote in message
      news:9A32B518-C241-4373-98AA-1B4BF435EF6C@mi crosoft.com...
      Hi Bogdan,
      >
      Please try the code below to check if page is valid or not in client side
      script.
      >
      <head runat="server">
      <title>Untitl ed Page</title>
      <script type="text/javascript">
      function ConfirmSave()
      {
      if (Page_IsValid )
      {
      return confirm('want to continue?');
      }
      else
      {
      return false;
      }
      }
      </script>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>
      <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
      <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
      runat="server" ControlToValida te="TextBox1"
      >
      ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
      <asp:Button ID="Button1" runat="server" Text="Button"
      OnClientClick=" return ConfirmSave();" UseSubmitBehavi or="False"/></div>
      </form>
      </body>
      >
      Regards,
      Manish
      >
      "Bogdan" wrote:
      >
      >Hi,
      >>
      >I have a OnClientClick script assigned to a button. From the script, I'd
      >like to check if RequiredFieldVa lidator attached to a textbox on the page
      >has failed. The Page_IsValid works fine with - for example - regex
      >validator but it does not work with the required field validator.
      >>
      >Any suggestions will be appreciated.
      >Thanks,
      >Bogdan
      >>
      >>
      >>

      Comment

      • =?Utf-8?B?UGlnbGV0?=

        #4
        Re: How to check from onclick if RequiredFieldVa lidator failed?

        Hi Bogdan.
        I have the same problem. I got around it by initializing Page_IsValid to
        false on the page. It is maybe not the best and cleanest solution but as far
        as I can see it works.

        "Bogdan" wrote:
        Manish,
        >
        Thanks for the reply. Unfortunately this does not work for me. It actually
        illustrates the problem that I've been having - i.e. Page_IsValid is true
        even when the text box is empty. So, regardless of the content of the text
        box I always get the 'want to continue?' message box.
        >
        Does this example behaves differently on your system? If yes, what browser
        and asp version do you use?
        I tested it in IE, FireFox, and Safari with asp 2.0 on the server.
        >
        Thanks again,
        Bogdan
        >
        "Manish" <Manish@discuss ions.microsoft. comwrote in message
        news:9A32B518-C241-4373-98AA-1B4BF435EF6C@mi crosoft.com...
        Hi Bogdan,

        Please try the code below to check if page is valid or not in client side
        script.

        <head runat="server">
        <title>Untitl ed Page</title>
        <script type="text/javascript">
        function ConfirmSave()
        {
        if (Page_IsValid )
        {
        return confirm('want to continue?');
        }
        else
        {
        return false;
        }
        }
        </script>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
        <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
        runat="server" ControlToValida te="TextBox1"

        ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
        <asp:Button ID="Button1" runat="server" Text="Button"
        OnClientClick=" return ConfirmSave();" UseSubmitBehavi or="False"/></div>
        </form>
        </body>

        Regards,
        Manish

        "Bogdan" wrote:
        Hi,
        >
        I have a OnClientClick script assigned to a button. From the script, I'd
        like to check if RequiredFieldVa lidator attached to a textbox on the page
        has failed. The Page_IsValid works fine with - for example - regex
        validator but it does not work with the required field validator.
        >
        Any suggestions will be appreciated.
        Thanks,
        Bogdan
        >
        >
        >
        >
        >
        >

        Comment

        Working...