Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:31:02+00:00 2026-06-14T18:31:02+00:00

I want to check the textbox value before postback occurs. I set the onClientClick

  • 0

I want to check the textbox value before postback occurs. I set the onClientClick value to my function but I don’t know how to pass the data to check, in this case I want to check the txt1 entered text.

<asp:textbox id="txt1" runat="server />

<asp:LinkButton ID="LinkButton1"
                runat="server"
                Text="Save" 
                onclick="Save"
                OnClientClick="javascript:check(WANT TO PUT TEXTBOX VALUE HERE);"
                />

My javascript:

function check(txt) {
 var pattern = /^[0-9]{1,11}(,[0-9]{0,2})?$/;
 if (!pattern.test(txt)) {
    return false;
 }
 else {
    return true;
 }
}

The issue is that this check function is used along the keypress event of the txt1 so I cant use:

function check(){
    var txt=$('#txt1').val();
}

The whole JS code:

$('#txt1').keypress(function (e) {
    var key = String.fromCharCode(e.which);
    var txt = $(this).val() + key;
    if (check(txt)) {
        // do sth
    } else {
        e.preventDefault();
        // do sth
    }
});

How can I tell the OnclientCLick function to get the txt1 value?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:31:03+00:00Added an answer on June 14, 2026 at 6:31 pm

    Something like that :

    <asp:textbox id="txt1" runat="server />
    
    <asp:LinkButton ID="LinkButton1"
                    runat="server"
                    Text="Save" 
                    onclick="Save"
                    OnClientClick="check(document.getElementById('<%=txt1.ClientID%>').value;)"
                    />
    

    Edit:
    Other methods :

    1. You can add it on server side : LinkButton1.OnClientClick="check(document.getElementById('" + txt1.ClientID + "').value;)";

    2. If you want to remain in the aspx page, you have to put a name of a javascript function in the OnClientClick and implement the javascript function in a script tag :

      <asp:LinkButton ID="LinkButton1"
                      runat="server"
                      Text="Save" 
                      OnClientClick="validate();"
                      />
      <script type="text/javascript">
          function validate() {
              alert(document.getElementById('<%=txt1.ClientID%>').value);
              return false;
          }
      </script>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't want check if an item with a value exists in the arraylist,
I want to check if a textbox value is empty and also if the
I want to check if user changes the value of a textbox. If the
I want to check the value of a textbox that whether it contains a
i want to validate textbox to check if the value entered is english and
I have an asp.net TextBox in which I want to check if the text
I want to do a Date Check on a TextBox with a onBlur event.
I have a check box, RequiredFieldValidator and textbox that have editmask extender I want
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I have a textbox, and whenever the value of the box changes, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.