Execute client side script when validation fails - how?

Discussion in 'ASP .Net' started by turboJeeper, Jan 17, 2007.

  1. turboJeeper

    turboJeeper Guest

    I have a form with 16 fields, 10 of which use the
    RequiredFieldValidator controls. I want to display a custom message
    when the validation fails. However, all the validators have
    ClientScript enabled so there is no postback.

    What can I hook into on the client side to execute other client side
    script (eg. show a hidden label or popup) if validation fails?
    turboJeeper, Jan 17, 2007
    #1
    1. Advertising

  2. turboJeeper

    turboJeeper Guest

    Can somebody help me out with this please?
    turboJeeper, Jan 18, 2007
    #2
    1. Advertising

  3. Sure,

    <asp:TextBox runat="server" ID="TextBox1" CausesValidation="false"/>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
    ControlToValidate="TextBox1"
    ErrorMessage="" Display="Dynamic" EnableClientScript="true"/>

    <asp:TextBox runat="server" ID="TextBox2" CausesValidation="false"/>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"
    ControlToValidate="TextBox2"
    ErrorMessage="" Display="Dynamic" EnableClientScript="true"/>

    <asp:TextBox runat="server" ID="TextBox3" CausesValidation="false"/>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3"
    ControlToValidate="TextBox3"
    ErrorMessage="" Display="Dynamic" EnableClientScript="true"/>

    <asp:Button runat="server" ID="Button3" Text="Click!" OnClientClick="return
    ValidateUserData();"/>

    <script type="text/javascript">
    function ValidateUserData()
    {
    for (i = 0; i < Page_Validators.length; i++)
    {
    ValidatorValidate(Page_Validators);
    }

    ValidatorUpdateIsValid();

    if (Page_IsValid == true)
    {
    return true;
    }
    else
    {
    alert('my custom code!');
    return false;
    }
    }
    </script>

    --
    Milosz


    "turboJeeper" wrote:

    > Can somebody help me out with this please?
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Feb 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,095
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. Magnus Blomberg
    Replies:
    3
    Views:
    717
    Magnus Blomberg
    Apr 14, 2005
  3. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    748
    Kevin Spencer
    Jun 2, 2005
  4. Boss302
    Replies:
    0
    Views:
    1,037
    Boss302
    Nov 21, 2006
  5. Bogdan
    Replies:
    2
    Views:
    646
    Bogdan
    Jun 9, 2008
Loading...

Share This Page