Validation control

Discussion in 'ASP .Net' started by simon, May 12, 2004.

  1. simon

    simon Guest

    I have textBox and field validator on my panel:

    <asp:TextBox id="txtID" Runat="server" Text="" Columns="5"></asp:TextBox>
    <asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server"
    ErrorMessage="Enter in the typeID."
    ControlToValidate="txtID"></asp:RequiredFieldValidator>

    Then I have INSERT and CANCEL buttons.

    If the user clicks INSERT button then the txtID should be client and server
    validate,
    but if user clicks CANCEL button, the validation should be omitted,
    panel.visible=false and I show him something else.

    Now If I clicks the Cancel button, the validation control doesn't allow me
    to post the page.

    Does anybody know the solution?

    Thank you,
    Simon
     
    simon, May 12, 2004
    #1
    1. Advertising

  2. Hi Simon,

    You can hide the error message of the RequiredFieldValidation control on the click of CANCEL button by using javascript.
    you need to create a function and insert a dummy value for the validation control.Then you need to call this function in the onclick event of the CANCEL Button.

    For example:

    <head><script lang="Javascript">

    function setDummy()

    {

    var Objtxt = document.getElementById("txtName")

    if (Objtxt!=null) {

    Objtxt.value ="dummy"

    }

    }

    </script></head><body>
    ...
    <asp:Button id="Button2" style="Z-INDEX: 104; LEFT:192px; POSITION: absolute; TOP: 112px" runat="server"
    Width="72px" Text="Cancel" onclick="javascript:setDummy();"></asp:Button>

    Now,you will not see the error message on the click of CANCEL button.

    Hope that helps
    Regards
    Lakshmi
     
    =?Utf-8?B?TGFrc2htaSBNdXJ0aHk=?=, May 12, 2004
    #2
    1. Advertising

  3. simon

    BlackMagic Guest

    You could set the CausesValidation property of your Cancel button to False.
    This has worked for me.

    HTH

    "simon" <> wrote in message
    news:%230oT9j$...
    > I have textBox and field validator on my panel:
    >
    > <asp:TextBox id="txtID" Runat="server" Text="" Columns="5"></asp:TextBox>
    > <asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server"
    > ErrorMessage="Enter in the typeID."
    > ControlToValidate="txtID"></asp:RequiredFieldValidator>
    >
    > Then I have INSERT and CANCEL buttons.
    >
    > If the user clicks INSERT button then the txtID should be client and

    server
    > validate,
    > but if user clicks CANCEL button, the validation should be omitted,
    > panel.visible=false and I show him something else.
    >
    > Now If I clicks the Cancel button, the validation control doesn't allow me
    > to post the page.
    >
    > Does anybody know the solution?
    >
    > Thank you,
    > Simon
    >
    >
     
    BlackMagic, May 12, 2004
    #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. Colin Mackay
    Replies:
    0
    Views:
    2,695
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,498
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    429
    Tommy
    Nov 29, 2003
  4. Lucas Tam
    Replies:
    2
    Views:
    1,115
    Lucas Tam
    Feb 26, 2004
  5. =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=

    Using Summary Validation control with server Custom validation

    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=, Oct 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    883
    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=
    Oct 15, 2004
Loading...

Share This Page