Start using JQuery in Web Application

Introduction

In this article we will see how we can use jQuery compatible script in a simple web application. jQuery is a buzzword today for writing script behind in mark up.

Create A Simple Web Application

Create a new web application and name it as JQuerySample.

image1.gif

Downloading jQuery from the below link and the necessary/minimum files to include to run jQueries.

The followings are the minimum files required to run jQuery.

jquery-1.3.2-vsdoc2.js

jquery-1.3.2.min-vsdoc.js

jquery-1.3.2.min.js

We will add the above files into one folder and name it as jQuery.

Add the script reference to the Web Application's header as follows:

<script src="jQuery/jquery-1.3.2.min.js" type="text/javascript"></script>

We will add a normal jQuery so that we can test the application.

Write any jQuery and run your application.

<script type="text/javascript" language="javascript">
        $(function() {
            $('#btnSubmit').click(function(event) {
                var txtMyInput = $('#txtInput')
                if (txtMyInput.val() == "") {
                    alert("Please Enter your name.");
                }
                else {
                    alert("Your name is: "+ txtMyInput.val());
                }
            });
        });
    </script>

If you look into the above jQuery you would find out that we have added one TextBox and one Button. If you look into the jQuery more deeply you would understand that we are checking the value of the Text input and validating it.

image2.gif


image3.gif

That's it you have successfully used jQuery in your asp.net application.

Keep scripting.


Similar Articles