560 likes | 713 Views
Developing Windows and Web Applications using Visual Studio.NET #10: Rich Web Forms with AJAX, jQuery and ASP.Net 4. Gerard Beckerleg. Session 10: Rich Web Forms with AJAX, jQuery and ASP.Net 4. Agenda. User experience and Usability AJAX Cross Page Post-backs Validation Groups
E N D
Developing Windows and Web Applications using Visual Studio.NET#10: Rich Web Forms withAJAX, jQuery and ASP.Net 4 Gerard Beckerleg
Agenda • User experience and Usability • AJAX • Cross Page Post-backs • Validation Groups • Maintaining Scroll Positions • Control Focus, Default Buttons, Error Focus • jQuery
Agenda • Client Script Handlers • XML Databinding • URL Rewriting/Mapping for Vanity Urls • ASP.NET 4 • SSW Rules to better…
Browsing experience - bad • http://www.ebay.com.au/ • Search drill down • http://secretgeek.net/W3SCG.asp • Code generator
Pain • Site is slow • Site is only static content • Site sends data back and forth • Flicker on load • Focus gets lost when working with page • Page gives no feedback during input • Losing context during navigation • Site is not alive
UX - Feel • Make the site feel alive • React quickly • Interact with the user • “Joy of use”
Browsing experience - Good • http://www.facebook.com/ • Photo gallery • http://www.live.com/?scope=images • Drill down • http://www.google.com/ig • http://maps.google.com/ • http://docs.google.com • http://secretgeek.net/wscg.htm • Code generator
What is AJAX? • Not a cleaning product... • A technology that enables rich interactive web applications • RIA • Asynchronous JavascriptAnd XML
How does AJAX work? • Page loads up [23KB] • Parts of the page use javascript to send a request to the webserver/webservice asking for data [3 KB] • The javascript on the page then renders the returned data on the current page without needing to refresh the whole page[8 KB]
How does ASP.NET AJAX work? • UpdatePanel • posts partial page back • ScriptManager • manages client script for ASP.NET AJAX
Why should I use AJAX? • We just retrieve the information we need • In the past we had to retrieve the whole page again! • Makes your applications more responsive • Users can browse around during AJAX call • Users don’t get lost by presenting them a new page
Who uses AJAX? • Google was a big proponent of AJAX • Almost all new sites use some form of AJAX • http://www.go2web20.net/
How do I use AJAX? • AJAX Extensions • http://ajaxcontroltoolkit.codeplex.com/ • Download the Control Toolkit
Recap - Microsoft AJAX • Easy way to enable AJAX on your web site • UpdatePanel • UpdateProgress • Many user contributed controls in the AJAX Toolkit. http://ajax.asp.net/ajaxtoolkit • Highlights: • Autocomplete (like google suggest) • Calendar • Filtered Text Box
Commercial AJAX Frameworks for .NET • Component Art • www.componentart.com • RadControls • www.telerik.com • Infragistics • www.infragistics.com
jQuery The SQL of JavaScript
JavaScript rules! • Maps.google.com
I HATE JavaScript ! • Big time! • Different Browser • Debugging • No compiling • Syntax • No intellisense • No static typing (duck typing!!) • No animations
What is jQuery? • Written in JavaScript • It is a lightweight JavaScript library (compressed base lib, 19 kb) • Helps developers & designers keep things simple and reusable • Visual Studio supports jQuery • Part of every web app / site • Intellisense support • A great library for developing AJAX-based application
Why JQuery?3 good reasons • 1- Cross-browser (IE 6.0+, Firefox 2+, Safari 3.0+, Opera 9.0+, Chrome) • 2- Powerful and easy to use • Same selectors as in CSS • Designers can learn it fast • More readable JavaScript code • 3 – Plug-ins • Tons of useful plug-ins and functionalities As per rule http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterWebsitesDevelopment.aspx#JQuery
1- Cross-browser • JavaScript window.onload = function() { alert(“Welcome"); } • JQuery $(document).ready(function() { alert(“Welcome!"); });
1- Cross-browser – Explanation • JavaScript • “onload” is only loaded when all images are loaded in the page • JQuery • “$(document).ready” is loaded as soon as the Document Object Model is ready • Similar to init() method in aspx page
2 – Powerful • Selector $(document).ready(function() { $("a").click(function() { alert("Hello world!"); }); }); • It will add any click-event to “a” tag
3. Plug-ins - Visually cool • Bubble Navigation (Hover each menu item to bubbling animation) - http://tympanus.net/Tutorials/BubbleNavigation/ • Quicksand (Click sort by to see shuffling animation) - http://razorjack.net/quicksand/ • Nivo Slider (Click on arrows to see sliding animation) - http://nivo.dev7studios.com/ • Sponsor Flip Wall (Click on each square to see flipping) - http://demo.tutorialzine.com/2010/03/sponsor-wall-flip-jquery-css/demo.php • Photo shoot Effect (Click on the big image to see photo shoot effect) -http://demo.tutorialzine.com/2010/02/photo-shoot-css-jquery/demo.html • HTC Clock - http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/ As per rule
3. Plug-ins - Technicallycool • Ajax Upload (show a preview of the file being upload) - http://www.zurb.com/playground/ajax_upload • AutoSuggestjQueryplugin (Type in the textbox to see suggestions) - http://code.drewwilson.com/entry/autosuggest-jquery-plugin • jQuery.popeye (Click the ‘Enlarge’ button to see effect) - http://dev.herr-schuessler.de/jquery/popeye/demo.html • Open Standard Media Player (jQuery + HTML5) - http://www.mediafront.org/project/osmplayer • jsPlumb connector - http://morrisonpitt.com/jsPlumb/html/jquery/demo.html • As per rule
References • jQuery official • http://jquery.com/ • jQuery UI library • http://jqueryui.com/ • Scott Gu’s Blog • http://weblogs.asp.net/scottgu/
What if JavaScript is turned off? • Parts or all of your website will not work
Solution • Check for JavaScript in page <body class=”no-js”> <script type="text/javascript"> document.getElementsByTagName("body")[0].className="jsEnabled"; </script> CSS #your-element { display: block; } body.jsEnabled #your-element { display: none; }
jQuery - Summary • JavaScript rules • JavaScript is terrible • Use jQuery instead of JavaScript • Cross browser compatibility • Easy to use • Tons of useful plug-ins
ASP.NET 4 • SEO – Routing & Permanent Redirect... Google Juice • Enhancements to Dynamic Data • MVC • QueryExtender Control • Deployment
Make URLs look nice • Ugly URLs • http://www.ssw.com.au/ssw/Products/ProdCategoryList.aspx?GroupCategoryID=10DOTNET • http://www.ssw.com.au/ssw/Products/ProdCategoryList.aspx?GroupCategoryID=1SQL • Nice URLs • http://www.ssw.com.au/Products/DotNet • http://www.ssw.com.au/Products/SQLServer P01
Response.Redirect protectedvoidApplication_BeginRequest(object sender, EventArgs e) { if (Request.FilePath == "/about-us.aspx") { Response.Redirect ("/about.aspx", true); } }
Response.RedirectPermanent protectedvoidApplication_BeginRequest(object sender, EventArgs e) { if (Request.FilePath == "/about-us.aspx") { Response.RedirectPermanent("/about.aspx", true); } } P02
Behind the scenes • What is the difference then? • Response.Redirect("/products.aspx", true); • Response.RedirectPermanent("/about.aspx", true);
Note: Can be done already with ASP.NET Response.Status = "301 Moved Permanently"; Response.StatusCode = 301; Response.AddHeader("Location","/new-page.asp"); Response.End();
404 Maintenance #1 • Add code to Global.asax to log 404s to a database (OLD_URL, NEW_URL) • Maintain the NEW_URL field • Change Global.asax to: • Look up the 404 in the database • If you find a broken link do a permanent redirect to the new URL • Otherwise insert broken link
404 Maintenance #2 • Bing Webmaster center • Google Webmaster tools • ELMAH • IIS SEO toolkit
IIS SEO toolkit • Recommendations and How-to’s • Make content search engine-friendly • Improve volume and quality of traffic • Control how search engines access and display Web content • Inform search engines about locations that are available for indexing • Show broken pages