Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ASP.NET jQuery Cookbook (Second Edition)

You're reading from   ASP.NET jQuery Cookbook (Second Edition) Over 60 recipes for writing client script in ASP.NET 4.6 applications using jQuery

Arrow left icon
Product type Paperback
Published in Feb 2016
Publisher
ISBN-13 9781782173113
Length 478 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Sonal Merchant Sonal Merchant
Author Profile Icon Sonal Merchant
Sonal Merchant
Sonal Aneel Allana Sonal Aneel Allana
Author Profile Icon Sonal Aneel Allana
Sonal Aneel Allana
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Getting Started with jQuery in ASP.NET FREE CHAPTER 2. Using jQuery Selectors with ASP.NET Controls 3. Event Handling Using jQuery 4. DOM Traversal and Manipulation in ASP.NET 5. Visual Effects in ASP.NET Sites 6. Working with Graphics in ASP.NET Sites 7. Ajax Using jQuery 8. Creating and Using jQuery Plugins Index

Adding jQuery to an empty ASP.NET web project using a script block

To create ASP.NET 4 .6 Web Applications, Visual Studio provides various ready templates such as Empty, Web Forms, MVC, Web API, and so on. This recipe will use the Empty template, which provides the developer with an empty project structure that consists of only the web.config file.

Tip

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Getting ready

Following are the steps to create a project by using Empty template:

  1. Create a new project in Visual Studio by going to File | New | Project..., as shown in the following screenshot:
    Getting ready

    Tip

    Website or web project?

    Instead of creating a new project, you can also create a new website. Unlike a project, a website does not contain a collective project file to track individual files in the application. To create a website, go to File | New | Web Site.... This will launch the New Website dialog box with the list of available templates. Select the ASP.NET Empty WebSite template.

  2. This will launch the New Project dialog box, as shown in the following screenshot. From the left-hand side panel, select your desired programming language, Visual C# or Visual Basic, and then, select ASP.NET Web Application from the middle panel:

    Getting ready

  3. Enter WebApplication1 (or any suitable name) in the Name field. Click on the Browse button to go to the desired Location where you would like to save the application. Click on OK.
  4. This will launch the Select a template dialog box, as shown in the following screenshot:
    Getting ready
  5. From ASP.NET 4.6 Templates, select Empty, and click on OK. Visual Studio will create an empty project in the Solution Explorer tab, as shown in the following screenshot:
    Getting ready

Note

In the remaining recipes, when asked to create a Web Application project using the Empty template, follow the steps listed in this section.

How to do it…

Following are the steps to include jQuery using script block:

  1. JavaScript files are usually placed in a folder named Scripts in the web application. So, in the Solution Explorer tab, right-click on the project and go to Add | New Folder from the menu:
    How to do it…
  2. Rename the folder to Scripts. Now, right-click on the Scripts folder, and go to Add | Existing Item... as shown in the following screenshot:
    How to do it…
  3. Now, browse to the location where you have saved the downloaded copy of the jQuery files (refer to the Downloading jQuery from jQuery.com recipe), and click on OK. It is recommended that you add both the uncompressed and compressed versions. The Scripts folder will be updated, as shown in the following screenshot:
    How to do it…
  4. Next, create a new web form in the project by right-clicking on the project and navigating to Add | New Item.... From the dialog box, select Web Form, and enter a suitable name for the web form, such as Default.aspx:
    How to do it…
  5. To use jQuery on the web form, simply drag and drop the required jQuery file, that is, uncompressed or compressed on the web form. Or alternatively, include the following <script> tag in the <head> element:

    For development mode, the code is as follows:

    <script src="Scripts/jquery-2.1.4.js"></script>

    For release mode, the code is as follows:

    <script src="Scripts/jquery-2.1.4.min.js"></script>
    How to do it…

See also

The Downloading jQuery from jQuery.com recipe

You have been reading a chapter from
ASP.NET jQuery Cookbook (Second Edition) - Second Edition
Published in: Feb 2016
Publisher:
ISBN-13: 9781782173113
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image