Skip to main content

JQuery and ASP.Net

Ive been playing with JQuery alot lately and am loving the ease of use and the feature rich toolset, you can get some realy good effects with it.

i know sometimes .net developers get, i dont know scared about trying new things that arnt born of microsoft, but JQuery is now being actively endorsed by microsoft and is actually shipped with the latest versions of the framework, so how do you use it.

1. If you dont have it get a copy of jquery.js its quite small (im currently using 'jquery-.3.2.min.js' which is 56Kb)
2. Include it in your web app
3. There are 2 ways to use it in a page
3a Add a script reference into your head section of the aspx page
<script src="Js cript/jquery -1.3.2.min.js" type="text/javascript"></script>
3b If you are using asp.net AJAX you can let the script manager handle it by:
3b.1 Adding a script manager to the form in the body of the aspx page
3b.2 Adding a scripts element
3b.3 Adding a script reference to the jquery file
3b.4 The result would look like this (remember it needs to go in side the pages form element
<asp:scriptmanager runat="server">
<scripts>
<asp:scriptreference path="~/Jscript/jquery-1.3.2.min.js">
</asp:scriptreference>
</scripts>

You are all set to use Jquery on the page

4. The most common way to initialise things is through the body onload, but this executes when the page is fully loaded, images and all, JQuery uses a special piece of script that executes when the page DOM is ready.

$(document).ready(function()
{
// do stuff when DOM is ready
});

This is where you can set styles, set up events to occur on different user actions all sorts of good stuff.
1st a couple of notes on the above code block:
1 it needs to be inside a sscript element
2 it needs to be located AFTER the scrip ref we declared in step 3 so if using the script manager it needs to be located inside the form after the script manager elements.
You can search the net for all the things you can do with JQuery, i wont repeat them all here, google is most definatly your friend.

But for now a simple example.

say you want to set up a click event to a group of radio buttons so that when clicked a javascript event is fired off to show or hide related DIV elements

<script type="text/javascript">
$(document).ready(function(){
$(":radio").click(function(event){RBEvent(this)});
$(".radioClass").hide();
});

function RBEvent(obj)
{
$(".radioClass").hide("slow");
$("#Div" + obj.id).show("slow");
}
</script>

And here is the aspx elements that go along with it

< asp:RadioButton ID="RBBus" runat="server" Text="Bus" GroupName="RB" />
< asp:RadioButton ID="RBTube" runat="server" Text="Tube" GroupName="RB" />
< div id="DivRBBus" class="radioClass">
Bus details
< br />
< /div>
< div id="DivRBTube" class="radioClass">
Tube details
< br />
< /div>

The neat thing that JQuery gives us, as in this example, is the ability to put all your page script into one place, and to have JQuery attach the events dynamically at run time making your javascript much easier to maintain. You could of course put all your script into a separate file as well which can be cached on the browser making the pages even quicker to load up.

Facebook

Facebook Recommendations

Followers


Web Designing In Karachi



Haroof.com


Politics blogs

My Zimbio

Email Subscribe

Enter your email address:

Watch online Live TV

Popular posts from this blog

BRITISH FIRM TO INTRODUCE DISSOLVABLE POLYTHENE BAGS IN KARACHI.

CNews Karachi. July 05: A Pakistani Scientist in Britain has invented a new chemical for processing plastic (polythene) bags which has the quality of dissolution after its use in 105 days.A manufacturing unit for these plastic bags was being set up in Turkey while interest has been shown in the setting up of a big unit and manufacturing firm’s head quarter in Karachi which will be used to supply such dissolvable polythene bags to Asian countries. The Director of UK based firm Bio Plast Biodegradable Plastics GL Punn while leading a 15 member delegation called on EDO Municipal Services City Government Masood Alam. The Executive Director of Bio Plast Pakistan Muhammad Hanif Awan and M. Sultan Mehmood Awan was also present on this occasion. The Director of Bio Plast informed the EDO Municipal Services about the characteristics of new chemical. He said that the firm was going to set up its first plant in Turkey which will be operative in next two months. The delegation also praised the vi

Admission Open in Class XI in Pre-Engineering, Pre-Medical, and Commerce Groups at BODMAS MODEL COLLEGE, North Nazimabad, Karachi

  Admission Open in Class XI in Pre-Engineering, Pre-Medical, and Commerce Groups at BODMAS MODEL COLLEGE, North Nazimabad, Karachi.

Matric General Group Result SECONDARY SCHOOL CERTIFICATE (S. S. C.) PART - II CLASS - X - 2010 (www.apnieyesp.com )

PASSED THE SECONDARY SCHOOL CERTIFICATE (S. S. C.) PART - II CLASS - X) ANNUAL EXAMINATION, 2010. ERRORS AND OMISSIONS EXCEPTED, CANDIDATES BEARING THE FOLLOWING ROLL NUMBERS ARE DECLARED TO HAVE PASSED THE SECONDARY SCHOOL CERTIFICATE (S. S. C.) PART - II CLASS - X) ANNUAL EXAMINATION, 2010. ------------------------------------------------- GENERAL GROUP (REG&PVT) --- GRADE..'A-ONE' ---- ----------------------- ( CANDIDATES SECURING TOTAL MARKS 680 AND ABOVE) MARKS SECURED BY THE CANDIDATES OUT OF TOTAL MARKS OF 850 ARE MENTIONED AGAINST EACH ROLL NUMBER IN BRACKET --------------------------------------------------- 601086 (689) XXX (XXX) XXX (XXX) XXX (XXX) XXX (XXX) XXX (XXX) 601327 (681) 363 (684) 364 (719) 407 (685) 664 (682) 788 (687) 601836 (692) 882 (683) XXX (XXX) XXX (XXX) XXX (XXX) XXX (XXX) 602315 (723) 316 (715) 320 (712) 321 (739) 325 (686) 326 (702) 602327 (683) 329 (70

Labels

Show more