{"id":484,"date":"2008-12-04T00:00:00","date_gmt":"2008-12-04T00:00:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/ext-framework-jquery-and-asp-net\/"},"modified":"2021-05-17T18:35:04","modified_gmt":"2021-05-17T18:35:04","slug":"ext-framework-jquery-and-asp-net","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/development\/dotnet-development\/ext-framework-jquery-and-asp-net\/","title":{"rendered":"Ext Framework, jQuery and ASP.NET"},"content":{"rendered":"<div id=\"pretty\">\n<h1>Ext Framework, <b>jQuery<\/b> and ASP.NET<\/h1>\n<p class=\"start\">With a little bit of magic you can do anything!\u00a0 I enjoy leaving the details of the intricate workings of object libraries to those lower level folks who enjoy typing code all day.\u00a0 If you&#8217;re like me, you&#8217;re only concerned with the higher level aspects of web development.\u00a0 I want to get things done fast, and <b>ASP.NET<\/b> and <b>JavaScript<\/b> libraries like <b>Ext<\/b> and <b>jQuery<\/b> make that possible.\u00a0 Some people cringe at JavaScript.\u00a0 I don&#8217;t claim to be an expert, but you don&#8217;t have to be a genius to use good JavaScript APIs.\u00a0 This article is aimed at those who would like to see greater things out of their presentation layers without having to write tremendous amounts of code to accomplish it.<\/p>\n<h1>Practical Overview<\/h1>\n<p class=\"MsoNormal\">Let me start by explaining the practical uses of <b>Ext <\/b>and <b>jQuery<\/b>. \u00a0The <b>Ext <\/b>Framework, for the most part, is geared at creating stunning user interfaces in a browser or AIR application that interact with the user much like what you would expect to see in a <b>Flash<\/b> or <b>Silverlight <\/b>application.\u00a0<\/p>\n<p class=\"illustration\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/614-image002.jpg\" alt=\"614-image002.jpg\" width=\"619\" height=\"249\" \/><\/p>\n<p class=\"MsoNormal\">\u00a0 The great thing about <b>Ext<\/b> and <b>jQuery<\/b> is that they run on the client, so any server side language can interact with them.\u00a0 ASP.NET can be used as a wrapper, like Coolite, which encapsulates the <b>Ext<\/b> Framework and supplies developers a standard way to implement Ext, or it can be used simply as a mechanism to interact with the client to create a customizable user experience.\u00a0 Either way you decide to use Ext, you will immediately see the power in its implementation.\u00a0<\/p>\n<p class=\"MsoNormal\">Like <b>Ext<\/b>, <b>jQuery<\/b> is a cross-browser JavaScript library that takes the strain out of doing complex procedures on the client.\u00a0 <b>jQuery<\/b> is implemented in a way that most object oriented developers are familiar with, making it easy to learn and use.\u00a0 Every method in <b>jQuery<\/b> returns the object itself, allowing you to chain methods together.\u00a0 In .NET, a simple chain could consist of turning an object into a string and then calling the substring method all within one line of code:<\/p>\n<pre>objectA.ToString().Substring(0, 3).\u00a0<\/pre>\n<p class=\"MsoNormal\">One advantage of both libraries is their awareness of page state. \u00a0Both <b>Ext<\/b> and <b>jQuery<\/b> use the document ready approach to ensure that page elements are ready to be manipulated before any calls are made.\u00a0 By using these two libraries, you immediately eliminate much of the time you would usually spend developing workarounds for common problems associated with DHTML and cross browser integration.\u00a0 You also give yourself a plethora of web 2.0 functions.<\/p>\n<h2>Getting Started<\/h2>\n<p class=\"MsoNormal\">To get started using <b>Ext<\/b> and jQuery, download the latest versions:<\/p>\n<ol>\n<li><b>Ext Framework SDK:<\/b>\u00a0 <a href=\"http:\/\/extjs.com\/products\/extjs\/download.php\">http:\/\/extjs.com\/products\/extjs\/download.php<\/a><\/li>\n<li><b>jQuery:<\/b>\u00a0 <a href=\"http:\/\/docs.jQuery.com\/Downloading_jQuery\">http:\/\/docs.jQuery.com\/Downloading_jQuery<\/a> (Optional, Ext contains a version of jQuery already)<\/li>\n<\/ol>\n<p class=\"MsoNormal\">Create a directory in the root of your web application called resources and then create a subdirectory called <b>jscript<\/b>.\u00a0 Copy the entire Ext Framework SDK folder into the <b>jscript<\/b> subdirectory.\u00a0\u00a0 To reference these script files anywhere in your application you will need to run your application from a web server.\u00a0 In the example I share in this article, I created a web application in IIS called <b>webportal<\/b>.\u00a0 So now, anywhere in my application I can reference <b>Ext<\/b> and <b>jQuery<\/b> by using the relative path of the application itself: <b>\/webportal\/resources\/jscript\/.<\/b><\/p>\n<p class=\"MsoNormal\"><b>Note:<\/b> Some <b>Ext<\/b> examples in the SDK contain php code, so some samples will not work unless your server can serve php.<\/p>\n<h2>Including the Script Libraries<\/h2>\n<p class=\"MsoNormal\">Ext is a little more problematical to include in your applications and it has a bigger footprint than jQuery; however, there are options that will improve performance if you do not require the use of the entire library.\u00a0 For example, you can build your own version of <b>Ext<\/b> using this wizard: http:\/\/extjs.com\/products\/extjs\/build\/.<\/p>\n<p class=\"MsoNormal\">Below I show how to include these libraries in your ASP.NET Master page.\u00a0 Please check out the source code to my example web portal as well for a more in depth view of the setup.\u00a0<\/p>\n<p class=\"MsoNormal\">At the time of this article the current version of <b>Ext<\/b> was 2.2.\u00a0 If a new version of <b>Ext<\/b> where to come out, all you would need to do is delete the old ext-2.2 directory and copy the new SDK in its place.\u00a0 You would then update the references below to the new version.\u00a0 Using ASP.NET you could retain the version in a settings file and reference that setting everywhere in your application.\u00a0 You will notice in my portal example that this is the approach I took.<\/p>\n<p class=\"MsoNormal\">Just below the script references are the style sheets for Ext.\u00a0 The first one is required.\u00a0 The second one is optional if you want to override the default theme with a custom theme.\u00a0 In this article I am using the slickness theme, which can be downloaded from the <b>Ext<\/b> website.<\/p>\n<pre class=\"lang:xhtml theme:github\">&lt;script type=\"text\/javascript\" src=\"\/webportal\/resources\/jscript\/ext-2.2\/adapter\/jQuery\/jQuery.js\"\r\n\u00a0 xml:space=\"preserve\"&gt;\r\n\u00a0 \/\/&lt;![CDATA[jQuery LIBRARY\r\n\u00a0 \/\/]]&gt;\r\n&lt;\/script&gt;\r\n\u00a0\r\n&lt;script type=\"text\/javascript\" src=\"\/webportal\/resources\/jscript\/ext-2.2\/adapter\/jQuery\/ext-jQuery-adapter.js\"\r\n\u00a0 xml:space=\"preserve\"&gt;\r\n\u00a0 \/\/&lt;![CDATA[EXT jQuery LIBRARY\r\n\u00a0 \/\/]]&gt;\r\n&lt;\/script&gt;\r\n\u00a0\r\n&lt;script type=\"text\/javascript\" src=\"\/webportal\/resources\/jscript\/ext-2.2\/ext-all.js\"\r\n\u00a0 xml:space=\"preserve\"&gt;\r\n\u00a0 \/\/&lt;![CDATA[EXT FRAMEWORK\r\n\u00a0 \/\/]]&gt;\r\n&lt;\/script&gt;\r\n\u00a0\r\n&lt;link href=\"\/webportal\/resources\/jscript\/ext-2.2\/resources\/css\/ext-all.css\"\r\n\u00a0 rel=\"stylesheet\" type=\"text\/css\" \/&gt;\r\n&lt;link href=\"\/webportal\/resources\/jscript\/ext-2.2\/resources\/css\/xtheme-slickness.css\"\r\n\u00a0 rel=\"stylesheet\" type=\"text\/css\" \/&gt;\r\n<\/pre>\n<p class=\"MsoNormal\">If you want to use the <b>jQuery<\/b> library or any other library that comes with <b>Ext<\/b> you will need to look at the INCLUDE_ORDER.txt file in the SDK.\u00a0 Notice that <b>jQuery<\/b> is included first.<\/p>\n<h1>Looking at the Code<\/h1>\n<p class=\"MsoNormal\">My example web portal uses an ASP.NET Master Page consisting of a two column content layout with a header, body and footer.\u00a0 <b>Ext<\/b> powers the entire layout.\u00a0\u00a0 Let&#8217;s examine the code.<\/p>\n<p class=\"MsoNormal\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/614-image003.gif\" alt=\"614-image003.gif\" width=\"630\" height=\"919\" \/><\/p>\n<p class=\"MsoNormal\">And this is what it produces (minus the lightshow in the upper right hand corner J):<\/p>\n<p class=\"illustration\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/614-image006.gif\" alt=\"614-image006.gif\" width=\"630\" height=\"442\" \/><\/p>\n<p class=\"MsoNormal\">The layout has the north (<b>BoxComponent)<\/b>, the west navigation panel, the center content panel and the south panel.\u00a0 The west and the south panel are collapsible.\u00a0 The viewport has the black slickness theme as defined in the xtheme-slickness stylesheet, which overrides the default look.\u00a0 You can download additional themes from the <b>Ext<\/b> website, or you can create your own.<\/p>\n<p class=\"MsoNormal\">So how do we interact with the panels?\u00a0 Let&#8217;s say you want to collapse a panel using a button.\u00a0 Remember those global panel variables?\u00a0 Here is some <b>jQuery<\/b> code:<\/p>\n<pre class=\"lang:xhtml theme:github\">&lt;div class=\"northRegion\" style=\"position: absolute; top: 5px; right: 0%; z-index: 50000;\"&gt;\r\n&lt;\/div&gt;\r\n&lt;input type=\"button\" value=\"North\" class=\"northRegionButton\" \/&gt;\r\n&lt;input type=\"button\" value=\"South\" class=\"southRegionButton\" \/&gt;\r\n&lt;input type=\"button\" value=\"West\" class=\"westRegionButton\" \/&gt;\r\n&lt;input type=\"button\" value=\"Center\" class=\"centerRegionButton\" \/&gt;\r\n\u00a0\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0 \/\/--------------------------------\r\n\u00a0 \/\/ jQuery Code\r\n\u00a0 \/\/--------------------------------\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0 $(document).ready(function(){\r\n\u00a0\u00a0\u00a0 \/\/--------------------------------\r\n\u00a0\u00a0\u00a0 \/\/ Setup North Region\r\n\u00a0\u00a0\u00a0 \/\/--------------------------------\r\n\u00a0\u00a0\u00a0 $(\"div.northRegion\").hide();\r\n\u00a0\u00a0\u00a0 $(\"div.northRegion\").html(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"&lt;div style='font-family: Tahoma; font-size: 11px; color: white; width: 800px; \" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"text-align: center;'&gt;&lt;h1 style='font-family: Impact; font-size: 50px;'&gt;North Region\" +\r\n\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"&lt;\/h1&gt;this is the Ext North Region\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 );\r\n\u00a0\u00a0\u00a0 \/\/--------------------------------\r\n\u00a0\u00a0\u00a0 \/\/ Events\r\n\u00a0\u00a0\u00a0 \/\/--------------------------------\r\n\u00a0\u00a0\u00a0 \/\/ North Region\r\n\u00a0\u00a0\u00a0 $(\"input.northRegionButton\").click(function(){ $(\"div.northRegion\").toggle(\"slow\"); \u00a0});\r\n\u00a0\u00a0\u00a0 \/\/ South Region (pSouth - Global Ext Panel defined in MasterPage)\r\n\u00a0\u00a0\u00a0 $(\"input.southRegionButton\").click(function(){ (pSouth.collapsed) ? pSouth.expand() : pSouth.collapse() });\r\n\u00a0\u00a0\u00a0 \/\/ West Region (pWest - Global Ext Panel defined in MasterPage)\r\n\u00a0\u00a0\u00a0 $(\"input.westRegionButton\").click(function(){ (pWest.collapsed) ? pWest.expand() : pWest.collapse() });\r\n\u00a0\u00a0\u00a0 \/\/ Center Region\r\n\u00a0\u00a0\u00a0 $(\"input.centerRegionButton\").click(function(){ \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 var $child = $(\"#center\").children();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 var $page0 = \"\/webportal\/resources\/jscript\/ext-2.2\/examples\/samples.html\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 var $page1 = \"\/webportal\/resources\/jscript\/ext-2.2\/examples\/collapsed.html\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 ($child[0].src.toLowerCase().match($page1) != null) ? $child[0].src = $page0 : $child[0].src = $page1; \r\n\u00a0\u00a0\u00a0\u00a0 });\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0 \/\/--------------------------------\r\n\u00a0 });\r\n\u00a0 \r\n&lt;\/script&gt; \r\n<\/pre>\n<p class=\"MsoNormal\">Inside the <b>jQuery<\/b> document ready function I included a setup section where I set up my <b><i>northRegion<\/i><\/b> div.\u00a0 Inside my <b><i>northRegion<\/i><\/b> div I want to toggle in and out some words from the right hand portion of the screen in a swoop like fashion when the <b><i>northRegionButton<\/i><\/b> is pushed.\u00a0 I setup the <b><i>northRegion<\/i><\/b> div and then defined a <b>jQuery<\/b> function for when the <b><i>northRegionButton<\/i><\/b> is pushed:<\/p>\n<pre class=\"lang:c# theme:vs2012\">$(\"input.northRegionButton\").click(function(){ $(\"div.northRegion\").toggle(\"slow\");\u00a0 });).<\/pre>\n<p>Inside the click event is logic to toggle in the <b><i>northRegion<\/i><\/b> div content.\u00a0 You can see at first I had to hide the <b><i>northRegion<\/i><\/b>, and then I defined what it contains and I defined an event for it.\u00a0 The result is pretty cool considering all the JavaScript code in the background making it work that I didn&#8217;t have to write myself.\u00a0<\/p>\n<p class=\"MsoNormal\">Now what about those global <b>Ext<\/b> panels?\u00a0 As mentioned previously, the south and west panels are collapsible.\u00a0 In the <b>jQuery<\/b> script above I make a basic condition for the two buttons in their click events.\u00a0 For example, the south panel (pSouth) I say &#8211; If the south panel is collapsed then expand it, else collapse it.\u00a0 I did the same for the west panel (pWest).\u00a0 You can handle any global <b>Ext<\/b> object with the same approach using jQuery.<\/p>\n<p><a href=\"http:\/\/www.simple-talk.com\/blogbits\/philf\/WebPortal.zip\">The source of the project is here (a 7 Mb zip file)<\/a><\/p>\n<h1>Using Coolite \/ ASP.NET<\/h1>\n<p class=\"MsoNormal\">Don&#8217;t want to bother with JavaScript?\u00a0 Well Coolite is your answer.\u00a0 I like Coolite, but I also like JavaScript so it really boils down to your preference.\u00a0 There are advantages to both approaches.\u00a0 Coolite is good because you can drag and drop server controls on your web form and setup the properties in Visual Studio just like you would any other server control.\u00a0 Coolite is free unless you want the source code.\u00a0 The biggest disadvantage of Coolite is when <b>Ext<\/b> upgrades.\u00a0 Because <b>Ext<\/b> is encapsulated in Coolite you have to wait for Coolite to upgrade before you can take advantage of the new features and fixes of Ext.\u00a0 Also, when Coolite does upgrade, you have to upgrade all your projects to use the new version of Coolite.\u00a0 It can become very tedious doing this.\u00a0 Basically with Coolite, you get the latest version now and stick with it for the long run.\u00a0\u00a0 Another disadvantage is the extent to what Coolite implements.\u00a0 Not all the features of <b>Ext<\/b> are available in Coolite controls.\u00a0 So with that said, don&#8217;t let my negativity dissuade you from checking out Coolite.\u00a0 It is very awesome and it continues to become more powerful as time goes on!<\/p>\n<h1>Links to consider<\/h1>\n<p class=\"MsoNormal\">The following will be helpful in your exploration of <b>Ext<\/b> and jQuery.<\/p>\n<ul>\n<li class=\"MsoNormal\">Ext API: <a href=\"http:\/\/extjs.com\/deploy\/dev\/docs\/\">http:\/\/extjs.com\/deploy\/dev\/docs\/<\/a><\/li>\n<li class=\"MsoNormal\">Ext Samples: <a href=\"http:\/\/extjs.com\/deploy\/dev\/examples\/samples.html\">http:\/\/extjs.com\/deploy\/dev\/examples\/samples.html<\/a><\/li>\n<li class=\"MsoNormal\"><b>jQuery<\/b> API: <a href=\"http:\/\/docs.jQuery.com\/Main_Page\">http:\/\/docs.jQuery.com\/Main_Page<\/a><\/li>\n<li class=\"MsoNormal\"><b>jQuery<\/b> Tutorial: <a href=\"http:\/\/docs.jQuery.com\/Tutorials\">http:\/\/docs.jQuery.com\/Tutorials<\/a><\/li>\n<\/ul>\n<h1>In Summary<\/h1>\n<p class=\"MsoNormal\">When you have deadlines and a surplus of projects on the backburner, <b>Ext<\/b> and <b>jQuery<\/b> are Godsends that save you time and your company money.\u00a0 Their intense functions will make your boss smile and your customers happy while making you look like a superhero.\u00a0\u00a0 I love the reaction I get when I implement these libraries at work.\u00a0 I take all the credit and I don&#8217;t feel ashamed!\u00a0 Happy coding!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are developing a browser-based application, or using Adobe AIR, then jQuery and Ext JS are prime choices for your framework. Of course you could code it all in raw Javascript and HTML but Daniel Penrod hasn&#8217;t got the time or the inclination to type code all day. He wants results!&hellip;<\/p>\n","protected":false},"author":47155,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143538],"tags":[4143,4156,4157,4911],"coauthors":[27395],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-dotnet-development","tag-net","tag-asp","tag-asp-net","tag-javascript"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/47155"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":6,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":73535,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/484\/revisions\/73535"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=484"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}