Thursday, 20 September 2012

How to use jQuery in ASP.NET

In this tutorial, We will learn how to use jQuery with ASP.NET.

For this your have to do some simple tasks.
  • First Add new website in visual studio and save it on your computer's File system.
  • Now Open your website and Create a new page or use Default.aspx page (which is created automatically for you by Visual Studio.) 
  • Now, We are going to use jQuery in our website so we have to import some jQuery files in our webpage. 
  • Visual studio 2010 already have these files for you in script folder. You can just drag and drop these files to your webpage's head section or manually put them. 
  • We will use jquery-1.4.1.js here ( You can also use other version of jquery file). 
  • After adding these files  Your page will look like this.

Now, In head section we will write jQuery code in script tag.  Here, A simple code of jQuery which changes Text of a Label on a HTML Button's click

Explanation : The Explanation is quite simple. When our webpage gets ready, a function is called which binds button1's click event to a function (event handler for click event ) and when
button is clicked, a function is called (or we can say an event is handled) which selects label1 and changes it's text property. That's All. The main advantage of jQuery is that it works the whole work without any post back at client-side. It was the very basic example of jQuery. Further i will post more useful examples.

No comments:

Post a Comment