0

I want to execute the following jquery function

$(document).ready(function () {
    $('.btnReset').click(function () {
        $('#txtFirstName').val('');
    });
});

The error is:

uncaught ReferenceError: $ is not defined.

on link button click, which is as follows;

<asp:LinkButton ID="btnReset" CssClass="btnReset" runat="server">RESET</asp:LinkButton>

But, I don't know why it is not working, Please assist me if anybody knows that. Thanks.

8
  • put an alert to check is it called?? Commented Jun 1, 2014 at 13:28
  • is #txtFirstName a client-side input (<input type="text" />), or an <asp:Textbox /> control? Commented Jun 1, 2014 at 13:31
  • Actually, it is giving me an error as "uncaught ReferenceError: $ is not defined." when i tried debugging it in browser. What's this? Commented Jun 1, 2014 at 13:34
  • 3
    If $ is not defined, you are either calling the script before jQuery has loaded or jQuery is not linked to the page. Commented Jun 1, 2014 at 13:36
  • @pete I tried writing the code in the head section of the page after all the scripts has been loaded, but still it is giving the same error. Commented Jun 1, 2014 at 13:43

1 Answer 1

2

asp.net changes Ids when rendering server side controls on client side, so i suspect that textbox value is not changed because of this so do like this:

$(document).ready(function () {
    $('.btnReset').click(function () {
        $("#<%=txtFirstName.ClientID%>").val('');
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

I am using the client side control.
If you add runat="server" the control is server side its obvious

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.