How to clear text field without firing validation??

3 posts, 0 answers
  1. Robert
    Robert avatar
    199 posts
    Member since:
    Aug 2009

    Posted 21 Nov 2011 Link to this post

    I have a text field which I attach a required field validator.  I have a button that initiates a clear() method but this is causing validation to fire.  Any idea of what might be wrong here?  I can change this to an asp textbox and set the value to the asp textbox without validation firing as usual.

    <telerik:RadTextBox Save="Text" ID="txtCode" onblur="UcaseTextbox(this, event)" runat="server" MaxLength="4" Width="50px" TabIndex="1"
                         CssClass="textUpper"
                          ToolTip="Vendor Code" CausesValidation="False">
                        </telerik:RadTextBox>
                        <asp:RequiredFieldValidator ID="reqCode" runat="server" ControlToValidate="txtCode"
                          Display="Dynamic" ErrorMessage="<br>Vendor Code required" 
                          SetFocusOnError="True" ForeColor="Red"></asp:RequiredFieldValidator>

    <asp:Button ID="btnClear" runat="server" Text="Clear" CausesValidation="false" UseSubmitBehavior="false" OnClientClick="ResetScreen(); return false;"
                                          ToolTip="Clear" TabIndex="3" />


    function ResetScreen() {
       $find("txtCode").clear();
    }
  2. Robert
    Robert avatar
    199 posts
    Member since:
    Aug 2009

    Posted 21 Nov 2011 Link to this post

    Ooops that wasn't the answer.
  3. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Nov 2011 Link to this post

    Hello Robert,

    Try accessing the RadTextBox as shown below.
    JS:
    function ResetScreen()
    {
       var txt = $find('<%= txtCode.ClientID %>').clear();
    }

    -Shinu.
Back to Top