Tuesday 12 May 2015

How to use JQuery in ASP.NET?




To use JQuery in ASP.NET follow these steps:

  1. Download JQuery from https://jquery.com/download/ . You can  Download the uncompressed, development jQuery 1.11.2  
  2. Open Visual Studio and Start New Project (ASP.NET Empty Web Application). Give an appropriate name.
  3. Copy the Downloaded JQuery file (jquery-1.11.2.js) to the project by right clicking the project name
  4. Now add an .aspx webform by again Right Clicking the project name->Add-> New Item
  5. Now Link the JQuery file to added webform by using Script Tag
  6. You can also use the JQuery provided by Google's CDN: 
  7. After linking the JQuery to webform, you can use it. But you have write the following code snippet to use the JQuery.

    Here document refers to current document object. This is to prevent any jQuery code from running before the document is finished loading (is ready).
    It is good practice to wait for the document to be fully loaded and ready before working with it. This also allows you to have your JavaScript code before the body of your document, in the head section. 
    Here are some examples of actions that can fail if methods are run before the document is fully loaded:
    • Trying to hide an element that is not created yet
    • Trying to get the size of an image that is not loaded yet
  8. For example to display a Welcome message when document is ready use the following: 

No comments:

Post a Comment