Click here to Skip to main content
12,446,418 members (55,444 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET .NET C#4.0
I want to use jquery .I tried following
<script type="text/javascript">
        $(document).ready(function () {
            $("#Button1").click(function () {
                alert("Hello world!");
            });
 
        });
    </script>

<pre lang="xml"<asp:Button ID="Button1" runat="server" Text="Button" />


while running i am getting an error

Microsoft JScript runtime error: '$' is undefined



pls tell how to use jquery in asp.net
Posted 23-Jan-13 0:44am
Comments
Sanjeev Alamuri 23-Jan-13 6:52am
   
Microsoft JScript runtime error: '$' is undefined means, u have to add jquery.js file in YOUR HEADER tag to initialize jquery.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You need to include the jQuery file in head section for executing the code.
How to include jQuery in ASP.Net project?[^].

You can include the script file directly in your page/master page, etc using:

<script type="text/javascript" src="/scripts/jquery.min.js"></script>

Us use a Content Delivery network like Google or Microsoft:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
or:
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script>

Comments
RaviRanjankr 23-Jan-13 7:02am
   
Nice Answer. My 5+
Tadit Dash 23-Jan-13 7:03am
   
Thanks @RaviRanjankr.
Espen Harlinn 23-Jan-13 7:23am
   
Well answered :-D
Tadit Dash 23-Jan-13 7:50am
   
Thanks @Espen Harlinn :P.
shivani 2013 23-Jan-13 7:25am
   
thanks
Tadit Dash 23-Jan-13 7:50am
   
Most welcome. My pleasure.
Thanks for accepting the answer.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

add jquery.js file in HEADR TAG.

Download from here.

jQUERY.JS[^]
  Permalink  
Comments
shivani 2013 23-Jan-13 7:25am
   
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100