<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ajax Matters &#187; Articles</title>
	<atom:link href="http://www.ajaxmatters.com/category/ajax-articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ajaxmatters.com</link>
	<description>Ajax</description>
	<lastBuildDate>Wed, 25 May 2011 09:39:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Getting Started with AJAX using Java : Tutorial</title>
		<link>http://www.ajaxmatters.com/2006/05/getting-started-with-ajax-using-java-tutorial/</link>
		<comments>http://www.ajaxmatters.com/2006/05/getting-started-with-ajax-using-java-tutorial/#comments</comments>
		<pubDate>Mon, 22 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=15</guid>
		<description><![CDATA[We learnt how AJAX works in previous articles; now we want to explore some techniques for using AJAX with Java technologies such as Java Server Pages (JSP), Java Server Faces (JSF) and others. The most common way of using AJAX &#8230; <a href="http://www.ajaxmatters.com/2006/05/getting-started-with-ajax-using-java-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We learnt how AJAX works in previous articles; now we want to explore some techniques for using AJAX with Java technologies such as Java Server Pages (JSP), Java Server Faces (JSF) and others.</p>
<p>The most common way of using AJAX with Java technologies is to use JavaScript. You need to have AJAX functions, such as, creating an XMLHttpRequest object for your browser, then using the object requests for a JSP page or Servlet (in general, for an URL), get the response and use it in your JSP web pages. For this, what I usually do is, I create a JavaScript file with all these functions and include this .js file in my web pages using a &lt;script&gt; tag, and use the functions mentioned there. This is a very common technique of using AJAX with JSP, and this is almost the same for PHP. The following example will clear the concept more.</p>
<p><strong>Problem:</strong> We need to get the server date time from a JSP page using AJAX.</p>
<p><strong>Solution:</strong> First we will create a JSP web page that will output server data time like the one below.</p>
<p class=textCode>&lt;%=new java.util.Date()%&gt;</p>
<p>Save the above line of code as index.jsp. The output will be as follows.</p>
<p><img height=258 src="http://www.ajaxmatters.com/images/java_ajax_intro1.jpg" width=501></p>
<p>Now create &nbsp;&nbsp;the necessary JavaScript functions, like the one I typically use.</p>
<p class=textCode>function createRequestObject(){</p>
<p>var req;</p>
<p>if(window.XMLHttpRequest){<br />//For Firefox, Safari, Opera<br />req = new XMLHttpRequest();<br />}<br />else if(window.ActiveXObject){<br />//For IE 5+<br />req = new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);<br />}<br />else{<br />//Error for an old browser<br />alert(&#8216;Your browser is not IE 5 or higher, or Firefox or Safari or Opera&#8217;);<br />}</p>
<p>return req;<br />}</p>
<p class=textCode>//Make the XMLHttpRequest Object<br />var http = createRequestObject();</p>
<p class=textCode>function sendRequest(method, url){<br />if(method == &#8216;get&#8217; || method == &#8216;GET&#8217;){<br />http.open(method,url);<br />http.onreadystatechange = handleResponse;<br />http.send(null);<br />}<br />}</p>
<p class=textCode>function handleResponse(){<br />if(http.readyState == 4 &amp;&amp; http.status == 200){<br />var response = http.responseText;<br />if(response){<br />document.getElementById(&#8220;ajax_res&#8221;).innerHTML = response;<br />}<br />}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />}</p>
<p>I usually save the above script as ajax.js. Add this JavaScript in your invoker JSP page (the page that will invoke the index.jsp to get the server date time) using AJAX.</p>
<p>The invoker JSP, caller.jsp –</p>
<p class=textCode>&lt;%@page contentType=&#8221;text/html&#8221;%&gt;<br />&lt;%@page pageEncoding=&#8221;UTF-8&#8243;%&gt;</p>
<p class=textCode>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;<br />&#8220;http://www.w3.org/TR/html4/loose.dtd&#8221;&gt;</p>
<p class=textCode>&lt;html&gt;<br />&lt;head&gt;<br />&lt;script src=&#8221;ajax.js&#8221;&gt;&lt;/script&gt;<br />&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&gt;<br />&lt;title&gt;JSP Page using AJAX&lt;/title&gt;<br />&lt;/head&gt;<br />&lt;body&gt;</p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a onclick=&#8221;sendRequest(&#8216;GET&#8217;,'index.jsp&#8217;)&#8221; href=&#8221;#&#8221;&gt;Server Date Time:&lt;/a&gt;<br />&lt;div id=&#8221;ajax_res&#8221;&gt;Server Date Time will replace this text.&lt;/div&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p>
<p>This caller.jsp has a &lt;div&gt; element with the id=’ajax_res’. When I the user clicked the link ‘Server Date Time:’ as shown below, the JavaScript function sendRequest from ajax.js would be called to get the data from ‘index.jsp’ using HTTP GET method. The output of caller.jsp before clicking the link is</p>
<p><img height=178 src="http://www.ajaxmatters.com/images/java_ajax_intro2.jpg" width=468></p>
<p>The output of caller.jsp after invoking the index.jsp using AJAX is</p>
<p><img height=176 src="http://www.ajaxmatters.com/images/java_ajax_intro3.jpg" width=480></p>
<p>This way you can use AJAX with JSP for retrieving information from Database or from any file kept in the server, or can send the user information to server and get the response.</p>
<p>//break//</p>
<p>There is also an OpenSource project called AjaxTags. This AJAX Tag Library is a set of JSP tags that simplify the use of AJAX technology in Java Server Pages. This tag library offers following tags for common AJAX functionality.</p>
<ul type=disc>
<li><strong>Autocomplete</strong>: retrieves a list of values that matches the string entered in a text form field to a data store, just plain old autocomplete!
<li><strong>Callout</strong>: displays a callout or popup balloon, anchored to an HTML element with an onclick event
<li><strong>Select/dropdown</strong>: based on a selection within a dropdown field, a second select field will be populated, important for narrowing down the selections, like after selecting a country from a list another list shows only the states of the selected country
<li><strong>Toggle</strong>: toggles a form field between true and false and at the same time switches an image between two sources
<li><strong>Update field</strong>: updates one or more form field values based on response to text entered in another field, this is very cool for huge forms with several text and select fields
<li><strong>Portlet</strong>: portlet-style capability from a AJAX-enabled JSP tag
<li><strong>Tab Panel</strong>: enable an AJAX-based set of property pages. </li>
</ul>
<p>This tag library relieves J2EE developers to write the necessary JavaScript to implement an AJAX-capable web form.</p>
<p>This implementation is a combination of Java classes and JavaScript source files. The Java code should be OS independent as there are no client side components. However, the Java is dependent on JDK 1.4+ and requires a Servlet container (like Tomcat) to run. The JavaScript should run in at least Firefox 1.0+ and Internet Explorer 5.0+.<br />To use AjaxTags tag library, first download it from <a href="http://ajaxtags.sourceforge.net/">http://ajaxtags.sourceforge.net/</a> and then copy the ajaxtags.jar into your WEB-INF/lib directory. Modify the web.xml for adding this tag library. Then add the dependency JavaScripts in your JSP pages. To learn more about this AjaxTags please visit the project homepage at <a href="http://ajaxtags.sourceforge.net/index.html">http://ajaxtags.sourceforge.net/index.html</a>.<br />There is another way of using AJAX with Java Server Faces user interface designs using Ajax4jsf. You can also use that. But the coolest AJAX tag library is jMaki. I’ll show you how to create a cool and nice with feature rich web page with jMaki and Netbeans 5.5 IDE in the next section.<br />According to the jMaki project team &#8211; jMaki is an Ajax framework that provides a lightweight model for creating JavaScript centric Ajax-enabled web applications using Java, PHP, and Phobos. To use jMaki with Netbeans IDE, first download the Netbeans module from <a href="https://ajax.dev.java.net/jmaki-plugin.html">https://ajax.dev.java.net/jmaki-plugin.html</a> and install the module. Installation procedure is described nicely in this link. <br />After installing jMaki module you can create your web 2.0 applications with just some drags and drops. Some examples are here.<br />First, run the Netbeans IDE. Create a new project from File menu. Select web application. Select jMaki Ajax Framework. It will ask you to choose the CSS layout, select Standard one. It will create the banners, a side bar, home page link, sitemap link etc.<br /><img height=423 src="http://www.ajaxmatters.com/images/java_ajax_intro4.jpg" width=573 border=0><br />Here, you can see the JSP code at the left and the Palette at the right. There are a lots of jMaki widgets at the palette. jMaki has widgets for Flickr, Google, Yahoo and others. Using Flickr widgets, you can create captcha, word art, and search for images very easily. Let’s create an image search using jMaki Flickr widget. Just drag the widget from palette and drop in your JSP page. Now save the project, build and run. A browser will be opened as below.<br /><img height=413 src="http://www.ajaxmatters.com/images/java_ajax_intro5.jpg" width=576 border=0><br />Enter some va<br />
lue in the edit box and click Search. It will get the images from Flickr using AJAX.<br /><img height=342 src="http://www.ajaxmatters.com/images/java_ajax_intro6.jpg" width=328 border=0><br />The JSP file looks like –<br /><span class=textCode>&lt;%@ taglib prefix=&#8221;a&#8221; uri=&#8221;http://jmaki/v1.0/jsp&#8221; %&gt;<br />&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;<br />&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</span></p>
<p class=textCode>&lt;html&gt;<br />&lt;head&gt;<br />&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;jmaki-standard.css&#8221; type=&#8221;text/css&#8221;&gt;&lt;/link&gt;<br />&lt;title&gt;Page Title&lt;/title&gt;<br />&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=iso-8859-1&#8243; /&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&lt;div class=&#8221;outerBorder&#8221;&gt;</p>
<p>&lt;div class=&#8221;header&#8221;&gt;<br />&lt;div class=&#8221;banner&#8221;&gt;Application Name&lt;/div&gt;</p>
<p>&lt;div class=&#8221;subheader&#8221;&gt;</p>
<p>&lt;div&gt;<br />&lt;a href=&#8221;mailto:feedback@youraddress&#8221;&gt;Feedback&lt;/a&gt; |<br />&lt;a href=&#8221;#&#8221;&gt;Site Map&lt;/a&gt; |<br />&lt;a href=&#8221;#&#8221;&gt;Home&lt;/a&gt;<br />&lt;/div&gt;</p>
<p>&lt;/div&gt; &lt;!&#8211; sub-header &#8211;&gt;<br />&lt;/div&gt; &lt;!&#8211; header &#8211;&gt;</p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div class=&#8221;main&#8221;&gt;<br />&lt;div class=&#8221;leftSidebar&#8221;&gt;</p>
<p>Sidebar Content Here</p>
<p>&lt;/div&gt; &lt;!&#8211; leftSidebar &#8211;&gt;</p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div class=&#8221;content&#8221; style=&#8221;height:400px&#8221;&gt;</p>
<p>&lt;a:widget name=&#8221;flickr.search&#8221; <br />args=&#8221;{<br />topic:&#8217;flickrSearch&#8217;, <br />columns:3, <br />count:9<br />}&#8221;<br />service=&#8221;/xhp&#8221;/&gt; </p>
<p>&lt;/div&gt; &lt;!&#8211; content &#8211;&gt;</p>
<p>&lt;/div&gt; &lt;!&#8211; main &#8211;&gt;<br />&lt;/div&gt; &lt;!&#8211; outerborder &#8211;&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p>
<p>//break//</p>
<p>Now let’s try another example. Pick the clock widget from the palette and drop it in your JSP code. Your code should look like this.</p>
<p class=textCode>&lt;div class=&#8221;content&#8221; style=&#8221;height:400px&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&lt;a:widget name=&#8221;dojo.clock&#8221;&nbsp; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>&lt;/div&gt; &lt;!&#8211; content &#8211;&gt; </p>
<p><img height=410 src="http://www.ajaxmatters.com/images/java_ajax_intro7.jpg" width=576 border=0></p>
<p>You can change the outlook of this widget also. To do this click within the code of the widget and then click jMaki button from Netbeans IDE as shown here.</p>
<p><img height=504 src="http://www.ajaxmatters.com/images/java_ajax_intro8.jpg" width=518 border=0></p>
<p>Change the clockType value to Gray. The changed JSP would be like –</p>
<p class=textCode>&lt;div class=&#8221;content&#8221; style=&#8221;height:400px&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&lt;a:widget name=&#8221;dojo.clock&#8221; args=&#8221;{clockType:&#8217;gray&#8217;}&#8221;/&gt;<br />&lt;/div&gt;</p>
<p>Save the changes and refresh the browser. The output would be –</p>
<p><img height=151 src="http://www.ajaxmatters.com/images/java_ajax_intro9.jpg" width=152 border=0></p>
<p>Here is a nice Yahoo slide bar for you.</p>
<p class=textCode>&lt;a:widget name=&#8221;yahoo.slider&#8221; /&gt;</p>
<p>Just add the above tag or drag it from palette. The output would be a nice simple slide bar.</p>
<p><img height=99 src="http://www.ajaxmatters.com/images/java_ajax_intro10.jpg" width=257 border=0></p>
<p>Now add a Tabbed View widget from the palette in your code. The JSP code would be:</p>
<p class=textCode>&lt;div class=&#8221;content&#8221; style=&#8221;height:400px&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&lt;a:widget name=&#8221;yahoo.tabbedview&#8221;<br />value=&#8221;{tabs:[<br />{label:'My Tab', content: 'Some Content'},<br />{label:'My Tab 2', content: 'Tab 2 Content'}<br />]<br />}&#8221; /&gt;</p>
<p>&lt;/div&gt; &lt;!&#8211; content &#8211;&gt; </p>
<p>You can change the labels from ‘My Tab’ to anything you need. You can also have as many tabs as required. The above code will create two tabs with labels and contents as described in the above code segment. Here is the output of this.</p>
<p><img height=347 src="http://www.ajaxmatters.com/images/java_ajax_intro11.jpg" width=575 border=0></p>
<p>Isn’t jMaki cool?! There are lots of other cool widgets for you. Explore all the widgets, you will love jMaki definitely. You can also add Google Search or Yahoo Search by simply just dragging and dropping. Also you can add Google Maps very easily in your web pages. You can have menus, calendars, trees, editor, editable table and lots of other cool widgets in your web application very easily. </p>
<p>There is good news for PHP developers. That is they can also use jMaki with PHP. I tried to describe different ways and techniques here in this article to use AJAX with JSP. You choose which one better fits your need. Now, go try out these solutions and learn AJAX.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/getting-started-with-ajax-using-java-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with Google Web Toolkit Tutorial</title>
		<link>http://www.ajaxmatters.com/2006/05/getting-started-with-google-web-toolkit-tutorial/</link>
		<comments>http://www.ajaxmatters.com/2006/05/getting-started-with-google-web-toolkit-tutorial/#comments</comments>
		<pubDate>Sun, 21 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=14</guid>
		<description><![CDATA[Building AJAX applications using Frameworks: Any developer will typically create his Ajax application by writing XHTML pages and JavaScript code with his favorite integrated development environment (IDE) or even text editors. A number of different libraries and frameworks exist which &#8230; <a href="http://www.ajaxmatters.com/2006/05/getting-started-with-google-web-toolkit-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><span class="textBoldBlue">Building AJAX applications using Frameworks: </span><br />
Any developer will typically create his Ajax application by writing XHTML pages and JavaScript code with his favorite integrated development environment (IDE) or even text editors. A number of different libraries and frameworks exist which allow programmers to use pre-designed JavaScript classes to implement otherwise time-consuming dynamic behaviors, such as drag-and-drop or sophisticated visual tree structures. Many are designed for developers who are already fairly well advanced in their JavaScript knowledge.<br />
These simple methods are changing as powerful tools proliferate for Ajax developers. The GWT takes a different approach to Ajax than most toolkits.</p>
<p><span class="textBoldBlue">The Google Web Toolkit&#8217;s Approach to Ajax:</span><br />
Using the GWT framework, you can design and program your user interface using only the Java language. You then use the GWT&#8217;s command-line tools to check the syntax of the Java classes, and finally automatically generate the JavaScript for the application&#8217;s client-side. The design of the user interface is very similar to using Java&#8217;s Swing API.</p>
<p><span class="textBoldBlue">Google Web Toolkit – An Overview</span><br />
Google Web Toolkit (GWT) is an open source Java development framework that lets you escape the matrix of technologies that make writing AJAX applications so difficult and error prone. With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice. When you deploy your application to production, the GWT compiler translates your Java application to browser-compliant JavaScript and HTML.</p>
<p>How GWT stands apart from other Frameworks?<br />
GWT has the Java-to-JavaScript compiler to distill your application into a set of JavaScript and HTML files that you can serve with any web server. This approach makes the app cross browser compatible, making the feveloper’s life much easier.</p>
<p><span class="textBold">GWT Architecture:</span><br />
GWT has four major components: a Java-to-JavaScript compiler, a &#8220;hosted&#8221; web browser, and two Java class libraries (one the JAVA API and another GWT API)</p>
<p>Google Web Toolkit Features:</p>
<p>- Open Source<br />
- Readymade, Dynamic, reusable UI components<br />
- RPC<br />
- Browser history management, debugging<br />
- Browser compatible<br />
- JUnit integration<br />
- Internationalization<br />
- Interoperability<br />
- Fine-grained control</p>
<p class="textBold">Debugging and Deploying GWT Applications:</p>
<p>GWT applications can be run in two modes:<br />
• Hosted mode &#8211; In hosted mode, your application is run as Java bytecode within the Java Virtual Machine (JVM). You will typically spend most of your development time in hosted mode because running in the JVM means you can take advantage of Java&#8217;s debugging facilities and remain within an IDE like Eclipse.<br />
• Web mode &#8211; In web mode, your application is run as pure JavaScript and HTML, compiled from your original Java source code with the GWT Java-to-JavaScript compiler. When you deploy your GWT applications to production, you deploy this JavaScript and HTML to your web servers, so end users will only see the web mode version of your application.<br />
To support hosted mode, GWT ships with a special web browser with hooks into the JVM. See the GWT architecture diagram below for more information.</p>
<p class="textBoldBlue">Getting Started:</p>
<p><span class="textBold">Basic Download: Installing Google Web Toolkit</span><br />
1. Install the Java SDK.If you don&#8217;t have a recent version of the Java SDK installed, download and install Sun Java Standard Edition SDK.<br />
2. Download Google Web Toolkit.Download the Google Web Toolkit package for your operating system.<br />
3. Unzip the Google Web Toolkit package.On Windows (or <a href="http://www.winserverhelp.com">Windows Server</a>), extract the files from gwt-windows-1.3.3.zip with a program like WinZip. On Mac and Linux, you can unpack the package with a command like<br />
tar xvzf gwt-mac-1.3.3.tar.gz</p>
<p><span class="textBold">Initial Setup under Various Environments:</span><br />
The CLI scripts are designed to be run from a command-line window such as Terminal in Mac OS X. They include:</p>
<p><em>applicationCreator</em>: This generates the skeleton directory structure for your application.</p>
<p><em>projectCreator :</em> This script generates a project skeleton, as well as Ant build files or Eclipse projects, according to what the command line specifies.</p>
<p><em>i18nCreator </em>: This creates some of the files required to use internationalized messages with GWT. The shortcut describes this application aspect in another section.</p>
<p><em>junitCreator</em> : The script can be used to get you started using JUnit with GWT.</p>
<p><span class="textBold">Kick Starting your First GWT Application:</span><br />
GWT ships with a command line utility called applicationCreator that automatically generates all the files you&#8217;ll need in order to start a GWT project. It can also generate Eclipse project files and launch config files for easy hosted mode debugging, as described below.</p>
<p>We will use applicationCreator for our demo application Open a Terminal or CLI window and type:<br />
<span class="textCode">applicationCreator -out /users/bruceperry/1ebooks/gwt -overwrite<br />
com.parkerriver.gwt.intro.client.GwtAjax</span></p>
<p>This command uses the provided applicationCreator shell script to create a skeleton directory structure. We will use this structure to develop an Ajax application inside a file named GwtAjax.java. The first option with the applicationCreator command, -out, specifies the directory for your application or project (it defaults to the existing directory, the one where applicationCreator resides, which is the top-level directory when you unpack GWT).<br />
The -overwrite option specifies that the command should overwrite any existing files. The final segment is the fully qualified name of the class where your application logic resides, usually representing the &#8220;entry point&#8221; class.</p>
<p>An entry point is the first screen the user interacts with in the Ajax application, such as a login window or a dashboard.</p>
<p>Based on the recommended GWT project structure, your main GWT application class should be in a subpackage client. You can create a new application called MyApplication with the command:<br />
applicationCreator com.mycompany.client.MyApplication<br />
The applicationCreator script will generate a number of files in src/com/mycompany/, including some basic &#8220;Hello, world&#8221; functionality in the class src/com/mycompany/client/MyApplication.java. The script also generates a hosted mode launch script called MyApplication-shell and a compilation script called MyApplication-compile.</p>
<p>//break//</p>
<p><span class="textBold">GWT Directory Structure:</span><br />
Whether you use the applicationCreator script or not, this is what your directory structure should look like. The client directory is where the Java class representing your user interface resides (such as the entry point class), and any of this class&#8217;s support classes.<br />
The public directory contains an HTML file that has the same name as your client class, but with a different suffix: GwtAjax.html. This file is only necessary if you are not dynamically generating your entire user interface with JavaScript. The HTML file allows you to enclose the JavaScript associated with your application widgets within a bigger design. This is typically the way you will go, as the designers will be building the XHTML pages, which will point to the GWT-generated JavaScript. The dynamically generated user interface aspects are usually enclosed by XHTML div tags in these pages.</p>
<p>To run your newly created application in hosted mode, run the MyApplication-shell script:<br />
<img src="../../images/gwt_intro_1.gif" alt="" /><br />
Try editing the files src/com/mycompany/client/MyApplication.java and src/com/mycompany/public/MyApplication.html to see how it changes your application.</p>
<p><span class="textBold">Creating an Application with Eclipse</span><br />
GWT ships with a command line utility called applicationC<br />
reator that automatically generates all the files you&#8217;ll need in order to start a GWT project. It can also generate Eclipse project files and launch config files for easy hosted mode debugging. To generate an Eclipse project for a new application, first use the projectCreator script to generate a shell Eclipse project for your application:<br />
projectCreator -eclipse MyProject<br />
Then generate your GWT application as described above, but with an additional -eclipse flag specifying the name of your Eclipse project:<br />
applicationCreator -eclipse MyProject com.mycompany.client.MyApplication<br />
When you&#8217;re done with these scripts, in addition to the MyApplication-shell and MyApplication-compile scripts, you should see .project, .classpath, and MyApplication.launch files in your current directory.<br />
To open your project in Eclipse, launch Eclipse and click the File -&gt; Import menu. Choose &#8220;Existing Projects into Workspace&#8221; in the first screen of the wizard, and enter the directory in which you genetrated the .project file in the next screen of the wizard. When you are complete, you should see your GWT project loaded into your Eclipse workspace:</p>
<p><img src="../../images/gwt_intro_2.gif" alt="" /></p>
<p><span class="textBold">Thinking beyond GWT:</span><br />
It is not at all necessary for us to stick to the console level; so many IDEs are available out there. To quote a few<br />
- Instantiations GWT Designer<br />
- JetBrains GWT Studio<br />
- GWT Widget Library<br />
- Wirelexsoft VistaFei for GWT</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/getting-started-with-google-web-toolkit-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling Complex DataTypes using ASP.NET AJAX</title>
		<link>http://www.ajaxmatters.com/2006/05/handling-complex-datatypes-using-asp-net-ajax/</link>
		<comments>http://www.ajaxmatters.com/2006/05/handling-complex-datatypes-using-asp-net-ajax/#comments</comments>
		<pubDate>Sat, 20 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=13</guid>
		<description><![CDATA[Use of complex data types in Ajax programming is a tricky issue. In many scenarios we need to communicate between the clientand server via strings only. In this article we discuss how ASP.NET AJAX handles complex data types. We wil &#8230; <a href="http://www.ajaxmatters.com/2006/05/handling-complex-datatypes-using-asp-net-ajax/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>ZH-TW</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:SplitPgBreakAndParaMark /> <w:DontVertAlignCellWithSp /> <w:DontBreakConstrainedForcedTables /> <w:DontVertAlignInTxbx /> <w:Word11KerningPairs /> <w:CachedColBalance /> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math" /> <m:brkBin m:val="before" /> <m:brkBinSub m:val=" " /> <m:smallFrac m:val="off" /> <m:dispDef /> <m:lMargin m:val="0" /> <m:rMargin m:val="0" /> <m:defJc m:val="centerGroup" /> <m:wrapIndent m:val="1440" /> <m:intLim m:val="subSup" /> <m:naryLim m:val="undOvr" /> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal" /> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8" /> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9" /> <w:LsdException Locked="false" Priority="39" Name="toc 1" /> <w:LsdException Locked="false" Priority="39" Name="toc 2" /> <w:LsdException Locked="false" Priority="39" Name="toc 3" /> <w:LsdException Locked="false" Priority="39" Name="toc 4" /> <w:LsdException Locked="false" Priority="39" Name="toc 5" /> <w:LsdException Locked="false" Priority="39" Name="toc 6" /> <w:LsdException Locked="false" Priority="39" Name="toc 7" /> <w:LsdException Locked="false" Priority="39" Name="toc 8" /> <w:LsdException Locked="false" Priority="39" Name="toc 9" /> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption" /> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title" /> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font" /> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle" /> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong" /> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis" /> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text" /> <w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1" /> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision" /> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph" /> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote" /> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2" /> <w:Ls<br />
dException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5" /> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6" /> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6" /> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6" /> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6" /> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6" /> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6" /> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6" /> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6" /> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6" /> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6" /> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6" /> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6" /> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6" /> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6" /> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis" /> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis" /> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QF<br />
ormat="true" Name="Subtle Reference" /> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference" /> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title" /> <w:LsdException Locked="false" Priority="37" Name="Bibliography" /> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading" /> </w:LatentStyles></xml><![endif]-->Use of complex data types in Ajax programming is a tricky issue. In many <span> </span><span> </span>scenarios we need to communicate between the clientand server via strings only.</p>
<p class="MsoNormal" style="text-align: justify;">In this article we discuss how <span> </span><a title="ASP.NET" href="http://www.aspnet101.com">ASP.NET</a> AJAX handles complex data types. We wil<span> </span>use a web service for Ajax communication which will be exposed to client using Script Manager.<span> </span>Although complex data types can be handled using JSON objects, <span> </span>Script Manager internally <span> </span><span> </span>JSON serialization <span> </span><span> </span>for handling complex data types; so will we will not concern ourselves with JSON inthis article.</p>
<p class="MsoNormal" style="text-align: justify;">Let’s assume we have a <strong>Public</strong> class Employee as below.</p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">public</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> <span style="color: blue;">class</span> <span style="color: teal;">Employee</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> name = <span style="color: blue;">string</span>.Empty;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> Address = <span style="color: blue;">string</span>.Empty;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> City = <span style="color: blue;">string</span>.Empty;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> zip = <span style="color: blue;">string</span>.Empty;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> [] phoneNumbers = <span style="color: blue;">null</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &quot;Cour&lt;br /&gt; ier New&quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span>Employee()</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{ </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span>Employee(<span style="color: blue;">string</span> Name,<span style="color: blue;">string</span>Address, <span style="color: blue;">string</span> City, <span style="color: blue;">string</span>zip, <span style="color: blue;">string</span> [] phoneNumber)</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">this</span>.Address= Address;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">this</span>.City= City;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">this</span>.name= Name;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">this</span>.zip= zip;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">this</span>.phoneNumbers= <span style="color: blue;">new</span> <span style="color: blue;">string</span>[phoneNumber.Length];</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">this</span>.phoneNumbers= phoneNumber;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> setValues()</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{ </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">string</span>_name = <span style="color: blue;">this</span>.name;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">string</span>_Address = <span style="color: blue;">this</span>.Address;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">string</span>_City = <span style="color: blue;">this</span>.City;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span><span style="color: blue;">string</span>_zip = <span style="color: blue;">this</span>.zip;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">string</span>[]_phoneNumbers = <span style="color: blue;">new</span> <span style="color: blue;">string</span>[<span style="color: blue;">this</span>.phoneNumbers.Length];</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>_phoneNumbers = <span style="color: blue;">this</span>.phoneNumbers;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">return</span><span style="color: maroon;">&#8220;SUCCESS&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: green;">//Writeyour logic for setting values.</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><br />
pan&gt;</span></p>
<p class="MsoNormal" style="text-align: justify;">In above class the elements which  need to be accessed in JavaScript are public – note we are not considering any function in a class.</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">We are going to expose a webservice to Script Manager for this article. So we also have a web service indemo code called <span> </span>“<strong>WebService.asmx</strong>”.</p>
<p class="MsoNormal" style="text-align: justify;">Following two namespaces arerequired to make a web service Ajax Enabled:</p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">using</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">System.Web.Script.Services;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">using</span><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"> System.Web.Script.Serialization;</span></p>
<p class="MsoNormal" style="text-align: justify;">Our web service class is as below:</p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">[<span style="color: teal;">WebService</span>(Namespace= <span style="color: maroon;">"http://tempuri.org/"</span>)]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>[<span style="color: teal;">WebServiceBinding</span>(ConformsTo= <span style="color: teal;">WsiProfiles</span>.BasicProfile1_1)]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>[<span style="color: teal;">GenerateScriptType</span>(<span style="color: blue;">typeof</span>(<span style="color: teal;">Employee</span>))]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>[<span style="color: teal;">ScriptService</span>]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: teal;">WebService</span> :System.Web.Services.<span style="color: teal;">WebService</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span><span style="color: blue;">public</span> WebService()</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: green;">//Uncommentthe following line if using designed components </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: green;">//InitializeComponent();</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>[<span style="color: teal;">WebMethod</span>]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> setValues(<span style="color: teal;">Employee</span>emp)</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">return</span>emp.setValues(); </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>[<span style="color: teal;">WebMethod</span>]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">public</span> <span style="color: teal;">Employee</span> getDefaultData()</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">string</span>[]PhnNum = { <span style="color: maroon;">&#8220;123&#8243;</span>,<span style="color: maroon;">&#8220;222&#8243;</span>,<span style="color: maroon;">&#8220;234&#8243;</span>};</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> &amp;n<br />
bsp; </span><span style="color: teal;">Employee</span>Emp = <span style="color: blue;">new</span> <span style="color: teal;">Employee</span>(<span style="color: maroon;">&#8220;Default Name&#8221;</span>,<span style="color: maroon;">&#8220;DefaultAddress&#8221;</span>,<span style="color: maroon;">&#8220;Default City&#8221;</span>,<span style="color: maroon;">&#8220;Default Zip&#8221;</span>,PhnNum);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">return</span>Emp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="text-align: justify;"><span>Below are the two extra lines we have added above the </span><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: teal;">WebService</span><span> class, this is to indicate that the web service will be called from JavaScript, and creates the corresponding script object of class<span> </span></span><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: teal;">Employee.</span><span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">[<span style="color: teal;">GenerateScriptType</span>(<span style="color: blue;">typeof</span>(<span style="color: teal;">Employee</span>))]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">[<span style="color: teal;">ScriptService</span>]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span>In the Demo, Employee and WebService classesare added under namespace Demo and are in the same file “webservice.asmx”.</span></p>
<p class="MsoNormal" style="text-align: justify;"><span>Our server side code ends here.<span> </span>Now we shall develop only client side code.</span></p>
<p class="MsoNormal" style="text-align: justify;"><span>Our form tag is as follow</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: maroon;">form</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> <span style="color: red;">id</span><span style="color: blue;">=&#8221;form1&#8243;</span><span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">asp</span><span style="color: blue;">:</span><span style="color: maroon;">ScriptManager</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;ScriptManager1&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">Scripts</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">asp</span><span style="color: blue;">:</span><span style="color: maroon;">ScriptReference</span> <span style="color: red;">Path</span><span style="color: blue;">=&#8221;JScript.js&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">Scripts</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">Services</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">asp</span><span style="color: blue;">:</span><span style="color: maroon;">ServiceReference</span> <span style="color: red;">Path</span><span style="color: blue;">=&#8221;WebService.asmx&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">Services</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">asp</span><span style="color: blue;">:</span><span style="color: maroon;">ScriptManager</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">br</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>Deal with<span style="color: red;">&amp;nbsp;</span>ComplexData Types<span style="color: blue;">&lt;</span><span style="color: maroon;">br</span><span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blu&lt;br /&gt; e;">&lt;</span><span style="color: maroon;">br</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">div</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">table</span> <span style="color: red;">border</span><span style="color: blue;">=&#8221;1&#8243;</span> <span style="color: red;">cellpadding</span><span style="color: blue;">=&#8221;0&#8243;</span> <span style="color: red;">cellspacing</span><span style="color: blue;">=&#8221;0&#8243;</span> <span style="color: red;">style</span><span style="color: blue;">=&#8221;width: 730px; height: 74px&#8221;</span> <span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">th</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span>Employee Name<span style="color: blue;">&lt;/</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">th</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span>Address1<span style="color: blue;">&lt;/</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">th</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span>City<span style="color: blue;">&lt;/</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">th</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span>Pin Code<span style="color: blue;">&lt;/</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">th</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span>Phone Number (seperate by &#8216;,&#8217;)<span style="color: blue;">&lt;/</span><span style="color: maroon;">th</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;</span> <span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;txtEmpName&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;txtAddress&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &quot;Courier New&lt;br /&gt; &quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;txtCity&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;txtZipCode&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">td</span> <span style="color: red;">align</span><span style="color: blue;">=&#8221;left&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;text&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;txtPhnNumber&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">td</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">tr</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">table</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">div</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">br</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;button&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;btnDefaultData&#8221;</span> <span style="color: red;">value</span><span style="color: blue;">=&#8221;Get Default Data&#8221;</span> <span style="color: red;">onclick</span><span style="color: blue;">=&#8221;_getDefaultData()&#8221;</span><span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=&#8221;button&#8221;</span> <span style="color: red;">id</span><span style="color: blue;">=&#8221;btnCallServer&#8221;</span> <span style="color: red;">value</span><span style="color: blue;">=&#8221;Call Server&#8221;</span> <span style="color: red;">onclick</span><span style="color: blue;">=&#8221;_sendDataToServer();&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">form</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span>In above code, we have used script manganer and registered our web service and JavaScript file.From here onwards we are goingto develop JavaScript </span></p>
<p class="MsoNormal" style="text-align: justify;"><span>Calling of WebService methods using JavaScriptand script manager is very simple, we just need to use the simple namespace sequence.</span></p>
<p class="MsoNormal" style="text-align: justify;"><span>e.g. If we want to call<span> </span></span><strong><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">getDefaultData</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"> </span><span>function of a webservice we simply need:</span></p>
<p class="MsoNormal" style="text-align: justify;"><strong><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">Demo.WebService.getDefaultData()</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">.</span></p>
<p class="MsoNormal" style="text-align: justify;"><span>If we want to add a response handler we justneed to specify the function name in bracess like</span><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"><br />
&gt; <strong>Demo.WebService.getDefaultData(OnSucceeded)</strong></span></p>
<p class="MsoNormal" style="text-align: justify;"><span>For the demo purpose our JavaScript contains threemain functions </span></p>
<p class="MsoListParagraphCxSpFirst" style="text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-family: Symbol;"><span>·<span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">_getDefaultData() – </span><span>This JavaScript function is used to call the web method<span> </span>get DefaultData. This Web Method returns default DataSet for the Employee class.</span></p>
<p class="MsoListParagraphCxSpLast" style="text-align: justify;"><strong><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">The JS function is as below</span></strong></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">function</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">_getDefaultData()</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;">// This function gets default data from server.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">Demo.WebService.getDefaultData(OnSucceeded)</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-align: justify;"><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">}</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span> </span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-family: Symbol;"><span>·<span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">_sendDataToServer() – </span><span>This JavaScript function is used to pass the clientside input to the server, or to the web method.</span></p>
<p class="MsoListParagraphCxSpLast" style="text-align: justify;"><span>The JS function is as below</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">function</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">_sendDataToServer()<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: green;">// Create aninstance of the Server side employee class.</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">var</span> obj = <span style="color: blue;">new</span> Demo.Employee();</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span>obj.name = window.document.getElementById(<span style="color: maroon;">&#8216;txtEmpName&#8217;</span>).value;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>obj.Address =window.document.getElementById(<span style="color: maroon;">&#8216;txtAddress&#8217;</span>).value;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>obj.City = window.document.getElementById(<span style="color: maroon;">&#8216;txtCity&#8217;</span>).value;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>obj.zip = window.document.getElementById(<span style="color: maroon;">&#8216;txtZipCode&#8217;</span>).value;</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>obj.phoneNumbers =window.document.getElementById(<span style="color: maroon;">&#8216;txtPhnNumber&#8217;</span>).value.split(<span style="color: maroon;">&#8216;,&#8217;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span><span> </span><span style="color: green;">// Call the Webservice method to send Client side values.</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>Demo.WebService.setValues(obj,OnSucceeded);<span> </span></span></p>
<p class="MsoListParagraphCxSpFirst" style="text-align: justify;"><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">}</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;"> </span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><strong><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">IN ABOVE FUNCTION CHECK THEWAY WE HAVE CREATED OBJECT OF AN EMPLOYEE CLASS. THIS EMPLOYEE CLASS EXISTS INC# CODE, BUT USING ASP.NET AJAX WE ARE ABLE TO CREATE AN INSTANCE ON CLIENTSIDE AS WELL.</span></strong></p>
<p class="MsoListParagraphCxSpMiddle" style="text-align: justify;"><strong><span> </span></strong></p>
<p class="MsoListParagraphCxSpLast" style="text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span style="font-family&lt;br /&gt;: Symbol;"><span>·<span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;">OnSucceeded(result,userContext,methodName) </span><span>– This JavaScript function is used to handle the response from the server. The function is as below</span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;">// This is thecallback function that </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;">// processes thecomplex type returned<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;">// by the Webservice.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;">function</span><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">OnSucceeded(result,userContext, methodName)</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">if</span>(methodName== <span style="color: maroon;">&#8220;getDefaultData&#8221;</span>)</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span> </span>window.document.getElementById(<span style="color: maroon;">&#8216;txtEmpName&#8217;</span>).value = result.name;</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>window.document.getElementById(<span style="color: maroon;">&#8216;txtAddress&#8217;</span>).value= result.Address; </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>window.document.getElementById(<span style="color: maroon;">&#8216;txtCity&#8217;</span>).value = result.City;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>window.document.getElementById(<span style="color: maroon;">&#8216;txtZipCode&#8217;</span>).value = result.zip;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">var</span>phnNum = <span style="color: blue;">null</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">for</span>(<span style="color: blue;">var</span> j = 0 ; j &lt; result.phoneNumbers.length; j++)</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">if</span>(j== 0) phnNum = result.phoneNumbers[j];</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">else</span>phnNum = phnNum + <span style="color: maroon;">&#8220;,&#8221;</span> +result.phoneNumbers[j]</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>window.document.getElementById(<span style="color: maroon;">&#8216;txtPhnNumber&#8217;</span>).value = phnNum;</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span>}<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"><span> </span><span style="color: blue;">else</span>alert(result);<span> </span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;">}</span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span>Refer the <a href="http://www.ajaxmatters.com/code/DealingWith_ComplexTypes_Demo.zip">Demo code </a>for better understanding of this code. </span></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/handling-complex-datatypes-using-asp-net-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The JDA Revolution</title>
		<link>http://www.ajaxmatters.com/2006/05/the-jda-revolution/</link>
		<comments>http://www.ajaxmatters.com/2006/05/the-jda-revolution/#comments</comments>
		<pubDate>Fri, 19 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=12</guid>
		<description><![CDATA[Synopsis: As the amount of logic implemented in javascript increases in response to demands in accessibility and client-side functionality, the opportunity for foot-shooting has increased exponentially. JDA is a nimble, kevlar-booted javascript message-passing kernel which manages communication between separate javascript &#8230; <a href="http://www.ajaxmatters.com/2006/05/the-jda-revolution/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><b>Synopsis: </b>As the amount of logic implemented in javascript increases in response to demands in accessibility and client-side functionality, the opportunity for foot-shooting has increased exponentially. JDA is a nimble, kevlar-booted javascript message-passing kernel which manages communication between separate javascript modules and enforces that modularization. JDA stands for Javascript Dataflow Architecture. It is an open standard developed by MAYA Design Inc.</p>
<h3>Benefits of Modularization<br /></h3>
<p>One would think that the Object Oriented revolution would have resulted in a sufficient modularization of software in itself, but recent years has seen the rise of several different types of &#8220;external&#8221; techniques to further separate parts of code from other parts, mostly for the sake of reuse, but also to release the programmers of the burden of tracking inter-connectivity of different parts of a system.</p>
<p>In the Java world, we have Spring as a very good example. Spring has many features, but one of the most obvious is automated configuration and &#8216;wiring&#8217; of loosely coupled objects. What does this mean? It means that you can write a java program as a couple of different objects that can use each other, and which can accept initialization data, but nothing explicit about initialization or connections to other objects is ever mentioned in the code itself.</p>
<p>Instead, Spring relies on external configuration files which can initialize and &#8216;wire&#8217; together java classes which themselves need not be aware of the Spring framework at all. This means that the programmers can focus more on the task at hand and leave interconnectedness and certain state issues to later wiring by Spring (or another container framework).</p>
<h3>Why modular Javascript? </h3>
<p>And more importantly, don&#8217;t we already have modular javascript? Take all those issues with prototype and mochikit way back when. They solved that with name spacing. Dojo had name-spacing since forever, and by having write dojo.byId(&#8216;foo&#8217;) you make sure that no parts of your framework will ever barge in on someone elses.</p>
<p>Well, the kind of modularization we&#8217;re talking about here is really of another kind, but name-spacing is an important technique which solves the problem of using several frameworks at the same time. Mostly <img src='http://www.ajaxmatters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But we already have widgets, you say. Again, taking dojo as an example, the widgets can be created programatically, or marked up as such in the page. They always have a DOM element to hang on, and they are both self-contained and hierarchical.&nbsp; Well, yes. Sure. But JDA is even more simple than widgets, though it uses similar techniques to mark things up.</p>
<p>The key to understand modular javascript in the JDA way is communication between modules. That&#8217;s what it&#8217;s all about. Most javascript programs are fairly small. Mostly this is due to a limited problem domain, but also to the expressiveness of modern scripting language. If you could take a JavaScript program and rewrite it in Java (for instance) it would generally be much longer. A good discussion on this can be found in <a id=o04o title="Paul Bucheit's blog" href="http://paulbuchheit.blogspot.com/2007/05/amazingly-bad-apis.html">Paul Bucheit&#8217;s blog</a> (focusing mainly on APIs) and in <a id=p0zt title="CMSWire's languages overview" href="http://www.cmswire.com/cms/industry-news/php-vs-java-vs-ruby-000887.php">CMSWire&#8217;s languages overview</a> .</p>
<p>As Javascript programs grow in both size and complexity, spaghetti code tends to be a looming problem. This is of course not unique to javascript, and neither is the JDA pattern, which has been properly implemented in python, for instance (Probably dropping the leading &#8216;J&#8217;).</p>
<p>The basic assumption behind modularization of code in the first place is to protect the programmer from him or herself, by enforcing or encouraging separation of concerns and to create &#8216;natural&#8217; borders between different parts of a system, the quick-fingered programmer receive cues where to put which new functionality.</p>
<p>In their <a id=z5-x title="thorough explanation of JDA" href="http://foundry.maya.com/jda/_resources/oopsla06.pdf">thorough explanation of JDA</a>, Seung Chan Lim and Peter Lucas defines JDA as &#8220;an ecosystem comprised of black box components operating within a JavaScript-based asynchronous message-passing environment&#8221;. By allowing for simple definitions of components, and a simple way to create multiple copies of the same, combined with a very simple message-passing abstraction, we get a compelling &#8220;workflow&#8221; where it costs little complexity to replace on of the components with another, or to make two or more connections from one components to other components, as needs for functionality in the application changes.</p>
<p>&nbsp;</p>
<h3>A Quick example<br /></h3>
<p>JDA uses the term &#8216;Infotron&#8217; for a javascript module. A web page can contain any number of infotrons. Each infotron is an instance of a javascript &#8216;Blueprint&#8217;. That&#8217;s not a hand-waving term either, by the way. If you have loaded the JDA runtime in a page, you can define a blueprint like this;</p>
<p><br style="BACKGROUND-COLOR: #ffffff">
<div style="MARGIN-LEFT: 80px"><span style="BACKGROUND-COLOR: #ffffff">BLUEPRINT(</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&#8220;~027F54CD51114410dB7A77CB8A523E340&#8243;, </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">{</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;iterms&#8221; : [],</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;oterms&#8221; : ["click_value_out"],</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;properties&#8221; : ["bname", "message"],</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;name&#8221; : &#8220;Simple Button&#8221;</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">},</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">function (Class) </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">{</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; Class.prototype._onInit = function(props)</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; {</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp; &nbsp; var self = this;</span> </div>
<div style="MARGIN-LEFT: 80px"><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp;&nbsp; function _onClick(e)&nbsp;&nbsp;&nbsp; </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp;&nbsp; {</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.postMessage(&#8220;click_value_out&#8221;, props["message"]); // postMessage is also provided to &#8216;this&#8217; by JDA</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style="BACKGROUND-COLOR: #ffffff"><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; this.button = document.createElement(&#8220;button&#8221;);</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; this.button.onclick = _onClick;</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; this.button.innerHTML = props["bname"]; // This is a named property which can be passed to us upon initialization</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; this.dom_node.appendChild(this.button); // this.dom_node is set by JDA to the element we are attached to</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; };</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">});</span></div>
<p>The abov<br />
e script defines a blueprint named &#8220;Simple Button&#8221;. You see that the first argument of the function BLUEPRINT in the JDA runtime is a unique identifier for the blueprint being defined. We could have written &#8220;xyzzy&#8221; instead and it would have worked, as long as no other blueprint were defined with that same UUID. General good practices, however recommend a proper UUID generated by the method of your choice.</p>
<p>//break//</p>
<h3>What is a blueprint? </h3>
<p>A blueprint is a template of a component which you might put in your web page. When the BLUEPRINT function is called in JDA, the blueprint is defined, and can then be used multiple times with the page. In the above example, this means you can put ten different buttons on the page, all implementing the same blueprint. It is roughly analogous to the relationship between a class and an instance in true OO languages.</p>
<p>The second argument is a javascript property map with four named values; iterms, oterms, properties and name. The name is pretty obvious. The iterms and oterms stand for input and output terminals.</p>
<p>Input terminals are names which can be accessed externally and which have handler functions. In this first example, we have conveniently dispensed with any input terminals, saving them for later <img src='http://www.ajaxmatters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Output terminals are, as you surely have understood by now, the counterparts of the input terminals. Their names are externally visible, and the JDA function <font color=#3366ff>postMessage(output_terminal, any_object); </font>can be used to send a javascript object (or literal, whatever) to that specific terminal. An output terminal can then be wired together with an input terminal.</p>
<p>After that comes any number of methods defined inside the blueprint. JDA provides special methods, one being the _onInit, which (if present) is called as soon as any infotron based on the blueprint is instantiated in the page.</p>
<p>The _onInit method first declares a simple event function, and then creates a button element whose onclick event is then tied to that function. What happens in the event function is that the provided property &#8220;message&#8221; is sent on the output terminal <span style="BACKGROUND-COLOR: #ffffff">&#8220;click_value_out&#8221; when the user clicks the button.</span></p>
<h3>Enter the Infotron </h3>
<p>Note that this is a blueprint definition and it does not make anything show up in the page at all. For that to happen we must create an Infotron. Confused about Infotrons and Blueprints? Think like this; The blueprint is like prototype, the infotron is like calling element.puff();&nbsp; You have to load prototype before you can use its goodies. But once you have, you can use them any number of times. Ok?</p>
<p>Let&#8217;s see a small example of an infotron using the above blueprint;</p>
<div style="MARGIN-LEFT: 80px">&nbsp;&nbsp;&nbsp; &lt;div id=&#8221;buttonexample&#8221;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; impl=&#8221;<span style="BACKGROUND-COLOR: #ffffff">~027F54CD51114410dB7A77CB8A523E340</span>&#8220;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; properties = &#8220;bname:&#8217;My Button&#8217;, message:&#8217;Foo!&#8217;&#8221;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; script=&#8221;SimpleButton.js&#8221;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/div&gt;</div>
<p>Not overly impressive, perhaps, but still a good start. Note that we are defining the infotron by using special tag properties. When JDA &#8216;boots&#8217;, it iterates all elements in the web page and registers all infotrons it finds. Since we might not have defined all blueprints we use prior to that (using the script tag in the head), we can also define the blueprint in the infotron definition. Note the names of the provided properties in the infotron definition, and that they are matched in the blueprint declaration.</p>
<p>We need more than one infotron to pass messages, though, so let&#8217;s define a simple blueprint which defines one input terminal and displays any message coming in inside a textarea;</p>
<div style="MARGIN-LEFT: 80px"><span style="BACKGROUND-COLOR: #ffffff">BLUEPRINT(</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&#8220;~197AA00D51114410d0A078238A52EF5F0&#8243;, </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">{</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;iterms&#8221; :<br />&nbsp; [<br /></span>&nbsp;&nbsp;&nbsp;&nbsp; ["message_in", "onMessage", 10]<br /><span style="BACKGROUND-COLOR: #ffffff">&nbsp; ],</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;oterms&#8221; : [],</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;properties&#8221; : [],</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; &#8220;name&#8221; : &#8220;Simple Show&#8221;</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">},</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">function (Class) </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">{</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; Class.prototype._onInit = function(props)</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; {</span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BACKGROUND-COLOR: #ffffff">this.area = document.createElement(&#8220;textarea&#8221;);</span><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp;&nbsp;&nbsp; this.dom_node.appendChild(this.area); </span><br style="BACKGROUND-COLOR: #ffffff"><span style="BACKGROUND-COLOR: #ffffff">&nbsp; };</p>
<p>&nbsp; Class.prototype.onMessage = function(msg)<br />&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp; this.debug(&#8220;Simple Show received message &#8216;&#8221;+msg+&#8221;&#8216;&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp; this.area.innerHTML = msg; // Ta-daa! <img src='http://www.ajaxmatters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <br />&nbsp; }<br style="BACKGROUND-COLOR: #ffffff"></span><span style="BACKGROUND-COLOR: #ffffff">});</span></div>
<div style="MARGIN-LEFT: 40px"></div>
<p><span style="BACKGROUND-COLOR: #ffffff"><br />This blueprint in contrast to the first does not declare any output terminals, but has instead one input terminal. Note that the input terminal declaration contains some more information than the output terminal; The first item &#8216;message_in&#8217; is the name of the input terminal, the &#8216;onMessage&#8217; item is the name of the handler function, which is called as soon as a message is sent to the terminal, and the third property is the queue size of the terminal. If several messages are sent while the infotron is disabled for some reason, the are queued up to the number defined.</p>
<p>With some luck you now begin to see how these two blueprints fit together. But first we need to revise out earlier infotron definition snippet. We&#8217;ll add an infotron implementing the second blueprint, but also define a connection from the first to the second.</p>
<p></span>
<div style="MARGIN-LEFT: 40px">&nbsp;&nbsp;&nbsp; &lt;div id=&#8221;buttonexample&#8221;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; impl=&#8221;<span style="BACKGROUND-COLOR: #ffffff">~027F54CD51114410dB7A77CB8A523E340</span>&#8220;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; properties = &#8220;bname:&#8217;My Button&#8217;, message:&#8217;Foo!&#8217;&#8221;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; connections=&#8221;&#8216;startup_message_out&#8217; : [['showexample', 'message_in']]&#8221;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; script=&#8221;SimpleButton.js&#8221;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/div&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;div id=&#8221;showexample&#8221;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; impl=&#8221;<span style="BACKGROUND-COLOR: #ffffff">~197AA00D51114410d0A078238A52EF5F0</span>&#8220;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; script=&#8221;SimpleButton.js&#8221;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/div&gt;</div>
<p>Before we do anything else, just observe the austere beauty of these two infotrons. The javascript logic is locked up in separate files, which can be combined and pre-loaded by a ser<br />
ver-side script if need be. Also, we are constraining the behavior of our scripts (not really, but we emphasize the encapsulation to the developer) inside the respective div elements. Further we are free to add CSS classes and styles which also separates logic from presentation.</p>
<p>JDA comes with a number of predefined blueprints, like a simple google map, form wrappers, a slideshow viewer, et.c. You also get a couple of convenience functions, like a debug version with copious output, and a debug output wrapper, which you can put in you pages for testing purposes, which redirects all debug output from both JDA itself and any &#8216;this.debug()&#8217; statements you have in your blueprints to an area of your choice.</p>
<p>//break//</p>
<p>For small demos, it is sometimes convenient to just define the blueprints inside script statements in the page itself, and skimp on the script property in the infotron definitions.</p>
<p>A sample page with the above blueprints, and debugging enable would then look like this;</p>
<div style="MARGIN-LEFT: 40px">
<div style="MARGIN-LEFT: 40px">&lt;!DOCTYPE html PUBLIC<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;-//W3C//DTD XHTML 1.0 Strict//EN&#8221;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#8221;&gt;<br />&lt;html&gt;<br />&lt;head&gt;<br />&lt;meta name=&#8221;uuid&#8221; content=&#8221;~019FF0001E0DDE94099163F8FEFA8802643&#8243; /&gt;</p>
<p>&lt;script language=&#8221;javascript&#8221; src=&#8221;JsStar.debug.js&#8221;&gt;&lt;/script&gt;<br />&lt;script language=&#8221;javascript&#8221; src=&#8221;init_jsstar.js&#8221;&gt;&lt;/script&gt;</p>
<p>&lt;script&gt;<br />BLUEPRINT(<br />&#8220;~027F54CD51114410dB7A77CB8A523E340&#8243;,<br />{<br />&nbsp; &#8220;iterms&#8221; : [],<br />&nbsp; &#8220;oterms&#8221; : ["click_value_out"],<br />&nbsp; &#8220;properties&#8221; : ["bname", "message"],<br />&nbsp; &#8220;name&#8221; : &#8220;Simple Button&#8221;<br />},<br />function (Class)<br />{<br />&nbsp; Class.prototype._onInit = function(props)<br />&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp; var self = this;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; function _onClick(e)&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.postMessage(&#8220;click_value_out&#8221;, props["message"]); // postMessage is also provided to &#8216;this&#8217; by JDA<br />&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; this.button = document.createElement(&#8220;button&#8221;);<br />&nbsp;&nbsp;&nbsp; this.button.onclick = _onClick;<br />&nbsp;&nbsp;&nbsp; this.button.innerHTML = props["bname"]; // This is a named property which can be passed to us upon initialization<br />&nbsp;&nbsp;&nbsp; this.dom_node.appendChild(this.button); // this.dom_node is set by JDA to the element we are attached to<br />&nbsp; };<br />});</p>
<p>BLUEPRINT(<br />&#8220;~197AA00D51114410d0A078238A52EF5F0&#8243;,<br />{<br />&nbsp; &#8220;iterms&#8221; :<br />&nbsp; [<br />&nbsp;&nbsp;&nbsp;&nbsp; ["message_in", "onMessage", 10]<br />&nbsp; ],<br />&nbsp; &#8220;oterms&#8221; : [],<br />&nbsp; &#8220;properties&#8221; : [],<br />&nbsp; &#8220;name&#8221; : &#8220;Simple Show&#8221;<br />},<br />function (Class)<br />{<br />&nbsp; Class.prototype._onInit = function(props)<br />&nbsp; {<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; this.area = document.createElement(&#8220;textarea&#8221;);&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; this.dom_node.appendChild(this.area);<br />&nbsp; };</p>
<p>&nbsp; Class.prototype.onMessage = function(msg)<br />&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp; this.debug(&#8220;Simple Show received message &#8216;&#8221;+msg+&#8221;&#8216;&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp; this.area.innerHTML = msg; // Ta-daa! <img src='http://www.ajaxmatters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <br />&nbsp; }<br />});</p>
<p>window.onload = function(e)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp; __star.boot();&nbsp;<br />}</p>
<p>&lt;/script&gt;<br />&lt;/head&gt;<br />&lt;body&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;div id=&#8221;buttonexample&#8221;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; impl=&#8221;~027F54CD51114410dB7A77CB8A523E340&#8243;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; properties = &#8220;&#8216;bname&#8217;:'My Button&#8217;,'message&#8217;:'Foo!&#8217;&#8221;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connections=&#8221;&#8216;click_value_out&#8217; : [['showexample', 'message_in']]&#8221;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/div&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;div id=&#8221;showexample&#8221;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; impl=&#8221;~197AA00D51114410d0A078238A52EF5F0&#8243;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/div&gt;</p>
<p>&lt;script language=&#8221;javascript&#8221; src=&#8221;debug.js&#8221;&gt;&lt;/script&gt;<br />&lt;div id=&#8221;debug&#8221; style=&#8221;position:absolute;bottom:20px;background-color:black;height:120px;width:100%;overflow:auto;&#8221;&gt;&lt;/div&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p>
</div>
</div>
<p>Here we see for the first time how JDA &#8220;boots&#8221;, by adding the __star.boot() call to window.onload. You framework of choice probably has a more generic onload handler for this event, but for our discussion, we stick to the basics.</p>
<p>If you want to see the demo in action, you can try it out <a id=x28s title=here href="http://www.mashupstation.com/station/article/article.html">here</a>. If you want to download a zipped file with the demo, do so <a id=uhsw title=here href="http://www.mashupstation.com/station/article/article.zip">here</a>.</p>
<p>Links to more information about JDA:</p>
<ul>
<li><a id=p8e3 title="JDA Wiki" href="http://www.assembla.com/wiki/show/aiRtQeWSGr26d-aaeP0Qfc">JDA Wiki</a>
<li><a id=s.el title="MAYA Design's JDA Foundry" href="http://foundry.maya.com/jda/">MAYA Designs JDA Foundry</a>
<li><a id=ck0v title="JDA Beta Google Group" href="http://groups.google.com/group/jdabeta">JDA Beta Google Group</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/the-jda-revolution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with Long Running Processes in ASP.NET</title>
		<link>http://www.ajaxmatters.com/2006/05/dealing-with-long-running-processes-in-asp-net/</link>
		<comments>http://www.ajaxmatters.com/2006/05/dealing-with-long-running-processes-in-asp-net/#comments</comments>
		<pubDate>Thu, 18 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=11</guid>
		<description><![CDATA[Introduction . Whether we use Ajax or not, if it is a very long running process the browser may show a time-out error. In case of ASP.NET AJAX if we use a script manager then we also have to define &#8230; <a href="http://www.ajaxmatters.com/2006/05/dealing-with-long-running-processes-in-asp-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>. Whether we use Ajax or not, if it is a very long running process the browser may show a time-out error.<br />
In case of <a href="http://www.aspnet101.com">ASP.NET </a>AJAX if we use a script manager then we also have to define the time-out for the request which can be difficult in the scenario where we cannot predict how long a process will take to execute.<br />
In this article we will discuss about this issue and how to use Ajax to handle long running process by using IAsyncResult and ICallbackEventHandler.</p>
<p>Web applications are based on a client-server architecture, so when the client hits the server the server will reply. If a long process is running on the server, then we may need some mechanism to determine when the long process is over. The long process can also delay the execution of other processes. To handle this issue we will use IAsyncResult . Using this interface and delegates we will able to run asyncronous processes on server side and invoke one method on server side while continuing with other tasks; once first method is complete it will automatically call another server method so that we can update some parameters say VAR1 and VAR2. And using ICallback  we can check for VAR1 and VAR2, as soon as we get  updated values, we will change status of long running method on client.</p>
<p><span class="textBoldBlue"><strong>Using IAsyncResult, delegates and AsyncCallback</strong></span></p>
<p>Classes which support asynchronous operations implement the IAsyncResult interface. IAsyncResult objects are passed back to methods invoked by AsyncCallback when an asynchronous operation completes. Classes which supports AsyncCallback<strong> </strong>in their methods return object of type IAsyncResult, for example<strong> </strong>- FileStream.BeginRead and FileStream.EndRead (these methods support AsyncCallback<strong> </strong>hence the return type is <strong> </strong>IAsyncResult). The same is true for BeginGetRequestStream method of WebRequest.<br />
If we look at the parameters in these methods there is an AsyncCallback parameter which is the method that gets called once Async method is over. In our code this method is <em>CallBackMethod</em>.</p>
<p><strong></strong>On server side, we have used a delegate and on the button click event the function named <em>DoSomething()</em> gets called. This function take cares of the <em>LongRunningMethod </em>registration for the <em>delegate </em>and invoking of <em>LongRunningMethod</em>. While invoking <em>LongRunningMethod </em>we register the AsyncCallback method i.e. <em>CallBackMethod</em><strong>.</strong></p>
<p><em>CallBackMethod </em>method can also be used to do other operations which may be dependent on the<em> LongRunningMethod</em><strong>.</strong></p>
<p><span class="textBoldBlue"><strong><br />
</strong></span><br />
We will create a simple <strong>LongRunningMethod</strong> as follows:<br />
<span class="textCode">private void LongRunningMethod(string name)<br />
{<br />
Thread.Sleep(60000 * 5);//This will run for 5 mins<br />
} </span></p>
<p>We will now declare a delegate for above function , parameters for the delegate and the method should be same: <span class="textCode"><br />
private delegate void LongRun(string name); </span></p>
<p>Implementation of the Async process on server side:<br />
<span class="textCode">private IAsyncResult DoSomething()<br />
{<br />
LongRun Long = new LongRun(LongRunningMethod);<br />
// Delegate will call LongRunningMethod<br />
IAsyncResult ar = Long.BeginInvoke(&#8220;CHECK&#8221;,new AsyncCallback(CallBackMethod),null); //”CHECK” will go as function parameter to LongRunningMethod<br />
return ar;<br />
//Once LongRunningMethod is complete CallBackMethod method will be invoked.<br />
}</span></p>
<p class="textCode">private void CallBackMethod(IAsyncResult ar)<br />
{<br />
AsyncResult Result = (AsyncResult)ar;<br />
LongRun Long = (LongRun)Result.AsyncDelegate;<br />
Long.EndInvoke(Result);<br />
}</p>
<p><em>Long.BeginInvoke</em> in <em>DoSomething</em> will invoke <em>LongRunningMethod</em> method. While implenting this just check the parameters for BeginInvoke in .NET.</p>
<p><em>CallBackMethod</em> gets called automatically after <em>LongRunningMethod. CallBackMethod </em>is used to end the invocation of the delegate.</p>
<p>On button click event we will call <em>DoSomething</em> function:<br />
<span class="textCode">protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
Response.Write(&#8220;Long running process is started&#8221;);<br />
Session["result"] = null;<br />
IAsyncResult res = DoSomthing();<br />
Session["result"] = res;<br />
}</span></p>
<p>Now we will implement ICallbackEventHandler for cheking status of the process. If you are not familiar with ICallBack please refer to my introductory article <a href="/articles/asp/icallback_intro_p1.aspx" target="_blank">Using ICallbackEventHandler in ASP.NET</a><br />
<strong></strong><br />
Add following lines of code on server side:<br />
<span class="textCode">public string GetCallbackResult()<br />
{<br />
if (res.IsCompleted)//Checking whether process is complete<br />
{<br />
IAsyncResult res = (IAsyncResult)Session["result"];<br />
if (res.IsCompleted)<br />
{<br />
return &#8220;SUCCESS&#8221;;<br />
}<br />
}<br />
return &#8220;FAIL&#8221;;<br />
}</span></p>
<p class="textCode">public void RaiseCallbackEvent(string args)<br />
{<br />
// Perform any operations here.<br />
}</p>
<p>And on client side we will add two JavaScript function:<br />
<span class="textCode">&lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221; &gt;<br />
&lt;asp:Button ID=&#8221;Button1&#8243; runat=&#8221;server&#8221; Text=&#8221;Button&#8221; OnClick=&#8221;Button1_Click&#8221; /&gt;<br />
&lt;div id=&#8221;Wait&#8221;&gt;Click button to start long running process.&lt;/div&gt;<br />
&lt;script language=&#8221;javascript&#8221;&gt;<br />
function CallServer()<br />
{<br />
window.document.getElementById(&#8220;Wait&#8221;).innerText = window.document.getElementById(&#8220;Wait&#8221;).innerText + &#8220;.&#8221;;<br />
&lt;%= ClientScript.GetCallbackEventReference(this,&#8221;", &#8220;ShowResult&#8221;, null) %&gt;;<br />
}<br />
function ShowResult(eventArgument,context)<br />
{<br />
if(eventArgument == &#8220;SUCCESS&#8221;) {alert(&#8216;Done&#8217;);};<br />
else setTimeout(&#8220;CallServer()&#8221;,60000);//Priodic call to server.<br />
}<br />
&lt;/script&gt;<br />
&lt;/form&gt;</span></p>
<p>After each 60sec we are invoking a callback to server which will check whether long running process is over or not. We can decide the callback period depending upon the long running process timing.</p>
<p>Please refer to the <a href="http://www.ajaxmatters.com/code/LongRunningProcess.zip">demo code</a> for better understanding of the Article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/dealing-with-long-running-processes-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update Multiple Page Elements Using The XMLHTTPRequest Object and JavaScript</title>
		<link>http://www.ajaxmatters.com/2006/05/update-multiple-page-elements-using-the-xmlhttprequest-object-and-javascript/</link>
		<comments>http://www.ajaxmatters.com/2006/05/update-multiple-page-elements-using-the-xmlhttprequest-object-and-javascript/#comments</comments>
		<pubDate>Wed, 17 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=10</guid>
		<description><![CDATA[In the development of Ajax application many times we will encounter following issues. The requiremnt to update multiple text boxes simultaneously. Fill more that one dropdown list. Update a combination of text boxes, dropdown lists and div tags. Call different &#8230; <a href="http://www.ajaxmatters.com/2006/05/update-multiple-page-elements-using-the-xmlhttprequest-object-and-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the development of Ajax application many times we will encounter following issues.</p>
<ul type=disc>
<li>The requiremnt to update multiple text boxes simultaneously.</li>
<li>Fill more that one dropdown list.</li>
<li>Update a combination of text boxes, dropdown lists and div tags.</li>
<li>Call different web pages and different webservices at the same time.</li>
</ul>
<p>Imagine the case of a financial data site (such as a stock market info site) with various regions of the page used for displaying data any taking user inputs. We may want to populate fill numerous div tags, textboxes and dropdown lists with real time data. If we loop the several requests and we will also have to check for timeout, if timeout occurs and no data is returned, then we will have to fire the same request again. It may end up that we have made 10 requests and 4-5 requests simply timeout because of network problems. If we dont loop then we will either get whole data or nothing (in which case there is only one more request to be made).</p>
<p>In this article we will discuss the XMLHTTPRequest object and JavaScript and develop a JavaScript class which can asychronously update multiple HTML elements. Also this class can be extended as per the requirements. I have used ASP.NET as the platform in this example but it does as the solution is just Javascript it can be applied to any web development platform.<br />&nbsp;<br />Regarding classes in JavaScript, technically there is no &#8216;class&#8217; in JavaScript but we can use a function as a class.</p>
<p>Consider the following code :</p>
<p class=textCode>function testClass()<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; this.Msg = &#8220;Hello&#8221;;<br />&nbsp;&nbsp;&nbsp; this.showMsg = function()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(this.Msg);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; var obj = new testClass();<br />&nbsp;&nbsp;&nbsp; obj.Msg = &#8220;HI&#8221;;<br />&nbsp;&nbsp;&nbsp; obj.showMsg();</p>
<p>In above script if we remove <strong>obj.Msg = &#8220;HI&#8221;; </strong>we will get an alert with text Hello.</p>
<p></p>
<p>We will now develop our JavaScript class step-by-step:</p>
<ol type=1>
<li>Include JS file and add the following code:</li>
</ol>
<p>&nbsp;&nbsp;<span class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function AjaxClass()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Method = &#8220;GET&#8221;;//OR &#8220;POST&#8221; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Async = true; //OR false (asynchronous or synchronous call) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.request = null;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;this.init = function() <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (window.XMLHttpRequest) // if Mozilla, Safari etc<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.request = new XMLHttpRequest();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (window.ActiveXObject)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { // if IE<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp; this.request = new&nbsp;&nbsp;&nbsp; ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.request = new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (e){}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(this.request)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; <br />this.request.onreadystatechange=this.handleResponse;<br />//we will develope <strong>this.handleResponse</strong> function in step 3 <br />this.request.open(this.Method, this.url , this.Async);<br />this.request.send(null);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; <br />}</span><br />Here we have created an XMLHTTPRequest object which is simply used to send a call to the server. The default method is <strong>GET</strong><strong> </strong>(this.Method = &#8220;GET&#8221;)<strong> </strong>and calling type is <strong>Ascynchronous </strong>(this.Async = true)</p>
<p>&nbsp;</p>
<ol type=1 start=2>
<li>In this step we will develop simple logic which will allow us to dynamically call Ajax function created in Step 1.</li>
</ol>
<p>For this one JSON (<a href="http://www.json.org/">http://www.json.org/</a>) object as follows.</p>
<p>&nbsp;</p>
<p class=textCode>this.JSONArray = {&nbsp; &#8220;Method&#8221; : &#8220;POST&#8221;, //Method type<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Async&#8221;&nbsp; : true, //Call type<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;CallPage&#8221; : &#8220;CallPage.aspx&#8221;, //page or webservice<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;Querystring&#8221; : &#8220;&#8221;, //Query string<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;dependentType&#8221; : null,//[0,1,2,3] for isEdit <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;isEdit&#8221;: [<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "textBoxId" : null, //0 then this element<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "dropDownId" : null, //1 then this element<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#038;n<br />
bsp;&nbsp;&nbsp;&nbsp;&nbsp; "default" : null, //2 then this element<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "misc":null //3 then this element<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]</p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</p>
<p>In above script we can set the default values for all elements. We will use these values to set response from the server to textboxes,drop down lists,Div tags, td tags etc. Using &#8220;CallPage&#8221; : &#8220;CallPage.aspx&#8221; we can define default server page and while calling Ajax function we can change this value to web method or to any other web page. <br />As we will proceed in this article we will examine how to change all the above values and how can we use it to update multiple elements.Also we will see that how to extend the class.</p>
<p></p>
<ol type=1 start=3>
<li>Recall from Step 1 : <span class=textCode>this.request.onreadystatechange = this.handleResponse; </span></li>
</ol>
<p>In this step we will develop <span class=textCode>this.handleResponse </span>function and in this function we will use the JSON object defined in Step 2. Whenever <span class=textCode>this.handleResponse</span> function gets called script loses the focus of&nbsp; <span class=textCode>this. </span>To keep track of this object we will asign it to some variable. i.e <span class=textCode>var self = this; // To lose of focus of the element</span>
<p>In this function we will be able to receive data from server. Once we receive the data we can manipulate it. This function will handle the responses from web services as well as from web pages. The web service always returns a response in the form of XML whereas the response from the webpage can be any format defined by web developer.</p>
<p>The function will be as follows:</p>
<p class=textCode>var self = this; // To handle lose of focus<br />this.handleResponse = function()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(self.request.readyState == 4 &amp;&amp; self.request.status == 200)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (window.ActiveXObject) // for IE<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var doc=new ActiveXObject(&#8220;Microsoft.XMLDOM&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc.async=&#8221;false&#8221;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doc.loadXML(self.request.responseText);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // code for Mozilla, Firefox, Opera, etc.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;var parser=new DOMParser();<br />&nbsp; var doc=parser.parseFromString(self.request.responseText,&#8221;text/xml&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var data&nbsp; = &#8220;&#8221;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(doc.documentElement) //Response from webservice<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data = doc.documentElement.childNodes[0].nodeValue;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else data = self.request.responseText; //from web page<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //data contains response text from the server</p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//At this point we have response from serve<br />//so here we will write our function to&nbsp;&nbsp;&nbsp; //manipulate the data. We will develop it in <br />//4th step.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch(e) {}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; <strong></strong></p>
<p><strong></strong>
<p>In the the 1st step we had: </p>
<p><span class=textCode>if(this.request)<br />{&nbsp;&nbsp; <br />this.request.onreadystatechange=this.handleResponse;<br />this.request.open(this.Method, this.url , this.Async);<br />this.request.send(null);<br />}</span></p>
<p>We will now modify this so that we can directly use the JSON array which we defined in 2nd step:</p>
<p class=textCode>if(this.request)<br />{&nbsp;&nbsp; <br />this.request.onreadystatechange=this.handleResponse;<br />this.request.open(this.JSONArray.Method, this.url , this.JSONArray.Async);<br />this.request.send(null);<br />}</p>
<p>While developing Ajax applications we ned to be aware of the following issues regarding domains:</p>
<ul type=disc>
<li>URL for XMLHTTPRequest object should belong to same domain.</li>
<li>Firefox and other browser doesn’t allow cross domain communication.</li>
<li>IE will show warning for cross domain communication.</li>
</ul>
<p>Thus our this.url = “http://myDomain/mysite/&#8221; + this.JSONArray.CallPage + this.JSONArray.Querystring;</p>
<p>e.g. &#8220;http://localhost/Demo/CallPage.aspx?&#8221;+this.JSONArray.Querystring;</p>
<p>Also whenever we want to call web methods like above example, we need to set following protocols under &lt;webServices&gt; in web.config file.</p>
<p><span class=textCode>&lt;webServices&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;protocols&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add name=&#8221;HttpGet&#8221;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add name=&#8221;HttpPost&#8221;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/protocols&gt;<br />&lt;/webServices&gt;</span></p>
<p><span class=textCode>//break//</span></p>
<ol type=1 start=4>
<li>Up to this point we have finished with development of the Ajax logic which will return a response. So now we need to develop logic for updating the HTML controls.</li>
</ol>
<p>&nbsp;</p>
<p>In<span class=t<br />
extCode> this.handleResponse</span> (step 3) we have seen that we get response in the “data” variable in JavaScript.<br /><strong>&nbsp;</strong><br />So now we have response from the server we will add following logic:</p>
<p><span class=textCode>switch(self.JSONArray.dependentType)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;case 0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;PopulateControls(self.JSONArray.isEdit[0].textBoxId,data);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //simple call to JS function<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PopulateControls(self.JSONArray.isEdit[0].dropDownId,data);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />}</span></p>
<p><span class=textCode><br />self.JSONArray.isEdit[0].textBoxId</span> will contain the id of the text box in which we need to update. And <span class=textCode>data </span>is the response from the server. In our switch we have simply used the elements of JSON object developed in Step 2. </p>
<p>We will now focus on initiating a request and setting the elements of the JSON objects.</p>
<p>First simply create object of our AjaxClass().</p>
<p class=textCode>var obj = new AjaxClass(); //Object creation<br />obj.JSONArray.Method = &#8220;GET&#8221;; //Setting Method <br />obj.JSONArray.isEdit[0].textBoxId=&#8221;txt1&#8243;;//Textboxid for response<br />obj.JSONArray.dependentType=0;//0-&gt;Textbox,1-&gt;drop downlist,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //2-&gt;tagId,3-&gt;Misc and so on<br />obj.init();//Initiate the AjaxCall</p>
<p>If <span class=textCode>obj.JSONArray.dependentType=1</span> then our <strong>switch </strong>case will not work for the textbox, but it will work for a dropdown list (check above <strong>switch </strong>case). This means we will have to set the dropdown in the JSON object:</p>
<p><span class=textCode>obj.JSONArray.isEdit[0].dropDownId=&#8221;ddl1&#8243;;</span></p>
<p>In this way we can define our own set of HTML controls to be updated.</p>
<p>In the same way we can also change all the default settings in JSON object of that class. </p>
<p>&nbsp;e.g. </p>
<p><span class=textCode>obj.JSONArray.Method = &#8220;GET&#8221;;<br />obj.JSONArray.CallPage = &#8220;Mywebservice/webMethod&#8221;;<br />obj.JSONArray.Querystring= &#8220;My querystring&#8221;;</span></p>
<p>For this URL will be : <span class=textCode>this.url = this.url + this.JSONArray.CallPage + this.JSONArray.Querystring ; </span><br /><strong></strong><strong></strong></p>
<p>In case of a web service we will have to set the CallPage element as we did in the above example.</p>
<p>For multiple textboxes use: <span class=textCode>obj.JSONArray.isEdit[0].textBoxId=&#8221;txt1$txt2$txtn&#8221;;//$ is a delimiter</span></p>
<p>While sending data from the server send it with the same delimiter,in such a way when we split obj.JSONArray.isEdit[0].textBoxId and response data on $; we will receive data and the appropriate textBoxId.</p>
<p>Now that we have different types like “txtbox(es) + drop down list(s) + div&#8221; in such case we can use &#8220;misc&#8221; option of isEdit element of JSON object.</p>
<p>And we can define our&nbsp; <strong>PopulateControls </strong>function the way we want. For ASP.NET we could also integrate ICallback logic for large data transfers.</p>
<p>&nbsp;</p>
<p>You can download the demo code <a href="http://www.ajaxmatters.com/code/XMLHTTPJSClassExt.zip">here</a> . This contains an ASP.NET project with the following files: </p>
<ul type=disc>
<li>XMLHTTPJsClass.js this file contains our AjaxClass() and funtion to populate textbox(es).</li>
<li>Demo.js this file contains 3 js function which initiates AjaxRequest with customization of&nbsp; request. Here you can find web page and webservice calls.</li>
<li>Default.aspx page</li>
<li>Webservice.asmx page.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/update-multiple-page-elements-using-the-xmlhttprequest-object-and-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chartered Financial Analyst &#8211; CFA Exam</title>
		<link>http://www.ajaxmatters.com/2006/05/chartered-financial-analyst-cfa-exam/</link>
		<comments>http://www.ajaxmatters.com/2006/05/chartered-financial-analyst-cfa-exam/#comments</comments>
		<pubDate>Wed, 17 May 2006 11:39:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CFA]]></category>

		<guid isPermaLink="false">http://www.ajaxmatters.com/?p=21</guid>
		<description><![CDATA[A lot more programmers and IT pro&#8217;s are studying for the Chartered Financial Analyst  CFA  Exam these days. The CFA Exam is a three stage  exam commencing with CFA Level 1 Exam which is held in June and December each &#8230; <a href="http://www.ajaxmatters.com/2006/05/chartered-financial-analyst-cfa-exam/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A lot more programmers and IT pro&#8217;s are studying for the Chartered Financial Analyst  <a href="http://www.analystrepublic.com/">CFA  Exam</a> these days. The CFA Exam is a three stage  exam commencing with <a href="http://www.analystrepublic.com/2010/05/cfa-level-1/">CFA Level 1 Exam</a> which is held in June and December each year.</p>
<p>CFA opens many horizons for developers as there is a constant requirement in the finance industry (despite the downturn) for systems development. In the last decade finance houses have started to look for developers with industry knowledge and the CFA designation is the best recognized qualification in finance. To qualify for the CFA designation an applicant is required to have a bachelors degree or at least four years of relevant experience.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/chartered-financial-analyst-cfa-exam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an AJAX-Enabled Grid using ICallbackEventHandler (Part 2)</title>
		<link>http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-2/</link>
		<comments>http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-2/#comments</comments>
		<pubDate>Tue, 16 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=9</guid>
		<description><![CDATA[In my previous article of Ajax enabled grid using ICallbackEventHandler I outline the creation of a grid with the following operations Sort the grid in ascending or in descending order by clicking on the arrows next to a column name. &#8230; <a href="http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my previous article of <a href="/articles/asp/ajax_grid_icallbackeventhandler_p1.aspx">Ajax enabled grid using ICallbackEventHandler</a> I outline the creation of a grid with the following operations </p>
<ul>
<li>Sort the grid in ascending or in descending order by clicking on the arrows next to a column name.</li>
<li>Change pages of the grid.</li>
<li>Change page length of the grid. </li>
</ul>
<p>In this article we will discuss editing the grid with the principal goal of <strong>doubleclicking on a grid cell to enable editing of that cell then edit the content of the cell and finally update server side data without refreshing the page. </strong></p>
<p>The key advantages of this grid are as follows</p>
<ul type=disc>
<li>Data will be bind to grid only once, i.e. on page load.</li>
<li>Only modified data goes to server to update the grid.
</li>
</ul>
<p>The basic UI will contain one Gridview and one update button. We will bind data to grid on page load. </p>
<ol type=1>
<li>Simply copy paste following code in the &lt;form&gt; tag of the page</li>
</ol>
<p>&nbsp; <span class=textCode>&lt;div id=&#8221;Gridview&#8221;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;asp:GridView EnableViewState=&#8221;false&#8221; runat=&#8221;server&#8221; id=&#8221;_grid&#8221; OnRowDataBound=&#8221;_grid_RowDataBound&#8221;&gt;<br />&lt;/asp:GridView&gt;<br />&lt;span id =&#8221;ServerMsg&#8221;&gt;&lt;/span&gt;<br />&lt;/div&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br /&gt;<br />&nbsp;&lt;input type=button value=&#8221;Update&#8221; onclick=&#8221;javascript: JSUpdateTable ();&#8221; /&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;script language=&#8221;javascript&#8221;&gt;<br />function UpdateGrid(args)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%= ClientScript.GetCallbackEventReference(this,&#8221;args&#8221;, &#8220;ShowResult&#8221;, null) %&gt;;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &lt;/script&gt;</span></p>
<p>We have activated RowDataBound event of the grid.</p>
<ol type=1 start=2>
<li>We will maintain a datatable, so that we can avoid fetching data from database. We will assume that we have a datatable and we define <strong>get </strong>and <strong>set </strong>&nbsp;properties for the table as follows.</li>
</ol>
<p>&nbsp;&nbsp; <span class=textCode>public DataTable _sampleData<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = (DataTable) Session["DataTable"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(dt == null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt = new DataTable();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Add(new DataColumn(&#8220;Contact&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name&#8221;,typeof(string)));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Add(new DataColumn(&#8220;Company Name&#8221;, typeof(string)));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Add(new DataColumn(&#8220;City&#8221;, typeof(string)));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Columns.Add(new DataColumn(&#8220;Country&#8221;, typeof(string)));</span></p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows.Add(new object[] { &#8220;Maria Anders&#8221; ,&#8221;Alfreds Futterkiste&#8221;,&#8221;Berlin&#8221;,&#8221;Germany&#8221;});<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(new object[] { &#8220;Ana Trujillo&#8221; ,&#8221;Emparedados y helados &#8220;,&#8221;México D.F.&#8221;,&#8221;Mexico&#8221;});<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows.Add(new object[] { &#8220;Antonio Moreno&#8221;, &#8220;Antonio Moreno Taquería&#8221;, &#8220;México D.F.&#8221;,&#8221;Mexico&#8221; });<br />Session["DataTable"] = dt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session["DataTable"] = value;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>We can write a function which will return a datatable, and the <strong>get </strong>property will simply return that table. We have used a session variable instead of viewstate to store the table; this is because we need to update data on the server side, if we use viewstate we would need to do post back of the page.</p>
<p>To bind this table to the grid we can simply set the datasource of the grid to the datatabe : <span class=textCode>_grid.DataSource = _sampleData;</span><br />And to set new data table we will add <span class=textCode>_sampleData = _tempTable;</span></p>
<p>Here _tempTable is the updated table after updating the grid on client side.</p>
<ol type=1 start=3>
<li>We will observe the typical ICallbackEventHandler procedure and add the following points on server side page, i.e. in c# code.</li>
</ol>
<ul>
<li>Inherit page class by ICallbackEventHandler interface :<span class=textCode> public partial class Default : System.Web.UI.Page , ICallbackEventHandler</span></li>
</ul>
<ul>
<li>Add <strong>RaiseCallbackEvent(string eventArgument) and GetCallbackResult() </strong>as follows :</li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class=textCode>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;public void RaiseCallbackEvent(string eventArgument)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] args = eventArgument.Split(&#8216;$&#8217;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args[0] == &#8220;updateTable&#8221;) updateTable(args[1]);<br />&nbsp;&nbsp;&nbsp; }</span></p>
<p class=textCode>&nbsp;&nbsp;&nbsp;&nbsp; public string GetCallbackResult()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br />&nbsp; }</p>
<p>The result is a global variable declared on the page.</p>
<p>We are following the same convention for <strong>RaiseCallbackEvent(string eventArgument) </strong>which we have used in my last article ( <a href="/articles/asp/ajax_grid_icallbackeventhandler_p1.aspx">Ajax enabled grid using ICallbackEventHandler</a> )</p>
<ol type=1 start=4>
<li>To make the cell editable on by a double-click we need to add javascript which will convert the cell in to textbox or a dropdownlist in such way that we can keep track of each updated cell. </li>
</ol>
<p>We can view a grid and and datatable as a two dimentional arrays with any cell being referenced by a row,column combination (i.e. <strong>row[i][j]</strong>).</p>
<p>As we have discussed earlier; we will look at the grid as a two dimentional array. Thus we will maintain unique id for each cell so that cell id will give the position of that cell in the datatable. <br />Here, understand that grid data is an exact copy of the datatable so row[i][j] in datatable will match with row[i][j] of grid.</p>
<ol type=1 start=5>
<li>In step 1 we activated RowDataBound event of the grid. In this step we will write the code for RowDataBound event. </li>
</ol>
<p class=textCode>Define _rowNumber as global variable for same page.<br />int _rowNumber = 0; </p>
<p class=textCode>protected void _grid_RowDataBound(object sender, GridViewRowEventArgs e)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (e.Row.RowType == DataControlRowType.DataRow)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; e.Row.Cells.Count; i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Row.Cells[i].Attributes.Add(&#8220;ondblclick&#8221;, &nbsp;&nbsp;&nbsp;&nbsp;&#8221;javascript:MakeCellEditable(this);&#8221;);<br />&nbsp;&nbsp; e.R<br />
ow.Cells[i].Attributes.Add(&#8220;id&#8221;, _rowNumber + &#8220;_&#8221; + i);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _rowNumber += 1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;}<br />}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>To make cell editable we have add:<br />&nbsp; <br /><span class=textCode>e.Row.Cells[i].Attributes.Add(&#8220;ondblclick&#8221;,&#8221;javascript:MakeCellEditable(this);&#8221;);</span></p>
<p>MakeCellEditable(this) will write this JavaScript function in next step.</p>
<p>To identify each cell as unique cell and to mach it with corrosponding datatable entry, we will give id to each cell in such a way that it will follow row[i][j] structure.<br />i.e.&nbsp;&nbsp; e.Row.Cells[i].Attributes.Add(&#8220;id&#8221;, _rowNumber + &#8220;_&#8221; + i);</p>
<p>And we are increasing row number each time. Observe the way we have given id, we will get [i][j] position just by spliting the is on “_”.</p>
<ol type=1 start=6>
<li>To make cell editable we will write following function in JavaScript</li>
</ol>
<p class=textCode>function MakeCellEditable(obj)<br />{<br />if(!window.document.getElementById(obj.id + &#8220;_input&#8221;)) <br />&nbsp;&nbsp; {<br />&nbsp;&nbsp; obj.innerHTML = &#8220;&lt;input id=&#8221;+ obj.id + &#8220;_input&#8221; + &#8221; type=text value=&#8217;&#8221; + obj.innerText + &#8220;&#8216;/&gt;&#8221;<br />&nbsp;&nbsp; }<br />window.document.getElementById(obj.id + &#8220;_input&#8221;).focus();<br />}</p>
<p>This function will convert the cell into text box and set focus in that text box. Check the way we have assinged theid to the text box (i.e.[i]_[j]_input obj is the cell)</p>
<p>//break//</p>
<ol type=1 start=7>
<li>Up to this point we have made the cell editable &#8211; now we need to select all updated values and send them to server to update the datatable. </li>
</ol>
<p>Onclick of the Update button has a javascript function named UpdateTable() (refer to step 1). This function is listed below:</p>
<p><span class=textCode>function JSUpdateTable()<br />{<br />var ddl = window.document.getElementById(&#8216;Gridview&#8217;);<br />var ddl1 = ddl.getElementsByTagName(&#8216;input&#8217;);<br />var data = &#8220;&#8221;;<br />for(i = 0 ; i &lt; ddl1.length ; i++)<br />&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ddlId[i] = ddl1[i].id; //ddlId is a global array in JS we will use it in step 9<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(i == 0 ) data = ddl1[i].id + &#8220;|&#8221; +&nbsp; ddl1[i].value; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else data = data + &#8220;~&#8221; + ddl1[i].id + &#8220;|&#8221; +&nbsp; ddl1[i].value;<br />&nbsp;&nbsp;&nbsp; }<br />UpdateGrid(&#8216;updateTable$&#8217;+data);<br />}</span> </p>
<ol type=1 start=8>
<li>The UpdateGrid function will call RaiseCallbackEvent(string eventArgument) on the server.</li>
</ol>
<p>Recall step 3 where we defined RaiseCallbackEvent(string eventArgument) and used the updateTable function. On the updateTable is a server-side function which is responsible for updating the Datatable. The function will be as follows.</p>
<p><span class=textCode>private void updateTable(string _data)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] _NewData = _data.Split(&#8216;~&#8217;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable _tempTable = _sampleData;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; _NewData.Length; i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string [] _changedTxt = _NewData[i].Split(&#8216;|&#8217;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] _rowCol = _changedTxt[0].Split(&#8216;_&#8217;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _tempTable.Rows[Convert.ToInt32(_rowCol[0])][Convert.ToInt32(_rowCol[1])] = _changedTxt[1];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _sampleData = _tempTable;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = &#8220;SUCCESS&#8221;;<br />&nbsp;&nbsp;&nbsp; } </span></p>
<p>In step 7 we have seen the javascript function JSUpdateTable() and how we send updated data in the format of string.</p>
<p>For further understanding lets assume that we are sending data to the server and &nbsp;_data = “0_1_input|ABC~3_3_input|XYZ”. Now in the above function observe how we manipulate and parse _data. </p>
<p>result = &#8220;SUCCESS&#8221;; result is a global string.</p>
<p>After updating the DataTable on the server-side we will send result to client, and if result = &#8220;SUCCESS&#8221; we will know that the datatable has been updated successfully.</p>
<p>The GetCallbackResult() function (ref. step 3) will send result string to client.</p>
<ol type=1 start=9>
<li>On the client-side we need one function which will automatically get called. In step one we have registered following function </li>
</ol>
<p><span class=textCode>function UpdateGrid(args)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%= ClientScript.GetCallbackEventReference(this,&#8221;args&#8221;, &#8220;ShowResult&#8221;, null) %&gt;;<br />&nbsp;&nbsp;&nbsp; }</span><br />(Please reffer my previouse AJAX Grid article for more details on this function)</p>
<p>ShowResult JavaScript function will get called automatically after the GetCallbackResult(), so now we will write this function.</p>
<p class=textCode>var ddlId = new Array();//Elements are added in step 7<br />// This array contain ids of textboxes <br />function ShowResult(eventArgument ,context)<br />{<br />&nbsp;&nbsp;&nbsp; formObj = window.document;<br />&nbsp;&nbsp;&nbsp; if(eventArgument == &#8220;SUCCESS&#8221;) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(j = 0 ; j &lt; ddlId.length ; j++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ids = ddlId[j].split(&#8220;_&#8221;);<br />formObj.getElementById(ids[0] + &#8220;_&#8221; + ids[1]).innerHTML = formObj.getElementById(ddlId[j]).value;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById(&#8216;ServerMsg&#8217;).innerText = &#8220;Data has been updated Successfully&#8230;&#8221;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />}</p>
<p>The above function is used only remove editable cells (i.e. to remove textboxes and to indicate that the server data has been updated)</p>
<ol type=1 start=10>
<li>On page_load we bind the grid :</li>
</ol>
<p class=textCode>protected void Page_Load(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!IsPostBack)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _grid.DataSource = _sampleData;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _grid.DataBind();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp; &nbsp;&nbsp;}</p>
<p class=TextBoldBlue>Further Enhancements</p>
<p>For editing the grid some points need to be considered. We have discussed only about using text boxes for editing but we could also use a dropdownlist or other controls.</p>
<p>If we are using paging and sorting updating a row in the datatable causes a problem for cell referencing. In this case we can add a column to the datatable which corresponds to table row, so if we sort the table and can still maintain the row number (i.e [i] in row[i][j] ). This column will be hidden in the grid so that we can use it for adding and deleting the the data as well.</p>
<p><span class=TextBoldBlue>Code</span>&nbsp;</p>
<p>The full code can be downloaded <a href="/code/AjaxifiedGrid.zip">here</a></p>
<p>The code contains two aspx pages</p>
<ul>
<li>EditGridDemo.aspx : This page contains the code in this article.</li>
<li>AjaxifiedGrid.aspx: This page contains the code for fully ajaxified grid.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to GWT Remote Procedure Calls (RPC)  (with example application)</title>
		<link>http://www.ajaxmatters.com/2006/05/introduction-to-gwt-remote-procedure-calls-rpc-with-example-application/</link>
		<comments>http://www.ajaxmatters.com/2006/05/introduction-to-gwt-remote-procedure-calls-rpc-with-example-application/#comments</comments>
		<pubDate>Mon, 15 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=8</guid>
		<description><![CDATA[Services in GWT Google Web Toolkit is a Web Application Framework dealing with Servers and Clients. When a Server is required to do some processing in a web-app Services must be used. A service is used to invoke server-side code &#8230; <a href="http://www.ajaxmatters.com/2006/05/introduction-to-gwt-remote-procedure-calls-rpc-with-example-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class=TextBoldBlue>Services in GWT</p>
<p>Google Web Toolkit is a Web Application Framework dealing with Servers and Clients. When a Server is required to do some processing in a web-app Services must be used. A service is used to invoke server-side code from the client (and vice-versa occasionally). </p>
<p>In GWT the Client side code pages run more like an application within the Client (Browser), so requesting the HTML pages from the Server is not necessary. But in common with all Server-Client Architectures, even GWT needs to contact the Server as they execute, this is carried out by Remote Procedure Calls (RPC). <br />&nbsp;<br /><span class=TextBoldBlue><strong>What is RPC?</strong>&nbsp;</span></p>
<p>RPC is a powerful technique for constructing distributed, client-server based applications. It is based on extending the notion of conventional or local procedure, so that the called procedure need not exist in the same address space as the calling procedure. GWT automatically generates most of the classes required for RPC.</p>
<p><img height=458 src="http://www.ajaxmatters.com/images/rpc1.JPG" width=596></p>
<p><span class=TextBoldBlue><strong>Services: Creation and Implementation</strong></span><strong>.</strong></p>
<p>Before getting into RPC, we will have a look at relationships between various classes and interfaces that we are creating for a service. With GWT Framework classes we create certain classes and interfaces for THE RPC Service.&nbsp;</p>
<ul type=DISC>
<li><strong>Service:</strong> This is our service definition interface. This defines the methods in our service and extends the RemoteService marker interface that indicates that this is a GWT RPC service. This is the synchronous definition and the server-side implementation must implement this interface. </li>
</ul>
<ul type=DISC>
<li><strong>ServiceAsync:</strong> The asynchronous definition of our interface. It must have the same methods as the synchronous interface, except for the requirement that all of its methods must have an AsyncCallback object as a parameter and the methods may not return anything. The naming convention recommended for this interface is to suffix the name of our synchronous interface with the word Async. </li>
</ul>
<ul type=DISC>
<li><strong>Service Impl:</strong> This is the server-side implementation of our service. This must extend RemoteServiceServlet and implement our synchronous interface—Service. </li>
</ul>
<p><span class=TextBoldBlue><strong>Remote Procedure Call &#8211; In Detail</strong>&nbsp;</span><br />&nbsp;<br /><strong>Client Creation:</strong> &nbsp;<br />To start with, we will create a client side code, by creating an Interface that extends the RemoteService Interface&nbsp;</p>
<ul>
<ul>
<p class=textCode>public interface MyService extends RemoteService {&nbsp;<br />&nbsp; public String myMethod(String s);&nbsp;<br />}</p>
</ul>
</ul>
<p>Any implementation of this Service must extend the RemoteServiceServlet and should Implement this Service Interface:&nbsp;</p>
<ul>
<ul class=textCode>
<p>public class MyServiceImpl extends RemoteServiceServlet implements MyService {&nbsp;<br />&nbsp; public String myMethod(String s) {&nbsp;<br />&nbsp;&nbsp; // Do something interesting with &#8216;s&#8217; here on the server.&nbsp;<br />&nbsp;&nbsp;&nbsp; return s;&nbsp;<br />&nbsp; }&nbsp;<br />}&nbsp;</p>
</ul>
</ul>
<p><strong>Call Progress:</strong></p>
<p>Now we need an Asynchronous Interface based on our Service Interface:</p>
<ul>
<ul>
<p><span class=textCode>interface MyServiceAsync {&nbsp;<br />&nbsp; public void myMethod(String s, AsyncCallback callback);&nbsp;<br />}&nbsp;</span></p>
</ul>
</ul>
<p>If we are using Asynchronous method calls, then we have to have callback object that can serve as a messenger to indicate when the call is completed. </p>
<p>Asynchronous methods are always void, only the callback object is used for communication to the caller.&nbsp;<br />&nbsp;<br />A service Interface and its Asynchronous counterpart have one simple relationship. The Asynchronous method must be in the same package as the Service Interface. If a service interface is called com.example.cal.client.AjaxMattersService, then the asynchronous interface must be called com.example.cal.client.AjaxMattersServiceAsync. </p>
<p>&nbsp;
<p>For each method in the Service Interface, &nbsp;</p>
<ul>
<ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=textCode> public ReturnType methodName(ParamType1 param1, ParamType2 param2);&nbsp;</span></p>
</ul>
</ul>
<p>the Asynchronous Interface must look something like this&nbsp;</p>
<ul>
<ul>
<ul>
<p><span class=textCode>public void methodName(ParamType1 param1, ParamType2 param2, AsyncCallback callback);&nbsp;</span></p>
</ul>
</ul>
</ul>
<p>In order to respond to client requests, the service ultimately needs to perform some processing. Such server-side processing occurs in the <em>service implementation</em>. A service implementation must extend RemoteServiceServlet and must implement the associated service interface. One important thing that to be noted here is that, the service implementation does <em>not</em> implement the asynchronous version of the service interface. to simplify matters we can say that every service implementation is ultimately a servlet, but rather than extending HttpServlet, it extends RemoteServiceServlet instead.&nbsp;</p>
<p>//break//<br />&nbsp;<br /><span class=TextBoldBlue><strong>How&nbsp;a&nbsp;Call is made?</strong>&nbsp;</span></p>
<p>The steps are pretty simple:</p>
<p>1. Instantiate the service interface using GWT.create(). </p>
<p>2. Specify a service entry point URL for the service proxy using ServiceDefTarget. </p>
<p>3. Create an asynchronous callback object to be notified when the RPC has completed and make a call.&nbsp;</p>
<p><span class=TextBoldBlue><strong>Serialization in GWT:</strong>&nbsp;</span></p>
<p>GWT tries really hard to make serialization as painless and as easy as possible, so while the rules regarding serialization are subtle, in practice the behavior becomes intuitive very quickly. That is the actually goal of GWT since it is involved in Web Applications. Serialization provides a simple and robust way to make object persistent and in case of RPCs, serialization plays a viral role. There are some conditions which GWT enforces for a type to be serializable and for it to be used in Service Interface.</p>
<p>Java objects and primitive types that can be serialized and transmitted via the GWT-RPC mechanism:&nbsp;</p>
<div align=left>
<ul>
<ul>
<table cellSpacing=0 width=0 border=2>
<tbody>
<tr vAlign=top>
<td width="43%" bgColor=#d9d9d9 height=34>Java primitive types</td>
<td width="56%" bgColor=#d9d9d9>boolean, byte, char, double, float, int, &nbsp; long, short&nbsp;</td>
</tr>
<tr vAlign=top>
<td bgColor=#d9d9d9 height=37>Java primitive wrapper types</td>
<td bgColor=#d9d9d9>Boolean, Byte, Character, Double, Float, Integer, Long, Short</td>
</tr>
<tr vAlign=top>
<td bgColor=#d9d9d9 height=40>Subset Java objects</td>
<td bgColor=#d9d9d9>Only ArrayList, Date, HashMap, HashSet, String, Vector</td>
</tr>
<tr vAlign=top>
<td bgColor=#d9d9d9 height=36>User defined classes</td>
<td bgColor=#d9d9d9>Any class that implements IsSerializable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
</tr>
<tr vAlign=top>
<td bgColor=#d9d9d9 height=35>Arrays</td>
<td bgColor=#d9d9d9>An array of any of the serializable types </td>
</tr>
</tbody>
</table>
</ul>
</ul>
</div>
<p>&nbsp;<br />&nbsp;
<p class=TextBoldBlue><strong>Serializable User-defined Classes</strong></p>
<p>A User Defined Class is said to be Serializable if it implements the IsSerializable interface. This is an interface that is part of the GWT library, and is used to signify that a class may be serialized via reflection techniques. This serves the same purpose as Java’s own java.io.Serializable interface, but is specific to GWT applications.&nbsp;</p>
<p>All non-transient fields in the class are serializable; by &#8216;<br />
non-transient field&#8217; we mean any field not using the transient modifier. GWT will also not serialize fields that have been marked as final, but don’t rely on this and be sure to mark all final fields as transient. The class has a zero argument constructor or no constructor at all.&nbsp;</p>
<p class=TextBoldBlue><strong>Polymorphism</strong></p>
<p>In terms of optimizations for the GWT compiler, it is good to be as specific as possible when specifying the types of your fields in the data object. For example it is common practice to specify java.util.List as a type instead of either ArrayList or Vector. The benefit of using a generalized type is that it allows you to change the underlying implementation without changing the type declaration. The problem is that when you generalize the type it is harder for the GWT compiler to optimize the code, and you often end up with larger JavaScript files. So the rule of thumb it to try to be as specific as possible in your typing.&nbsp;</p>
<p>&nbsp;<br /><strong class=TextBoldBlue>Arguments</strong></p>
<p>By Arguments, here we mean the Type Arguments. Suppose if we have a case where we use collections, we can’t be very specific, in that case the conflict arises. In order to solve this, GWT provides an annotation that allows us to let the compiler know what types of objects are being used in the collection. As this is not a Java 5 annotation, we have to provide an inside Java Comment.</p>
<ul>
<ul>
<p><span class=textCode>/**&nbsp;<br />* @gwt.typeArgs &lt;java.lang.String&gt;&nbsp;<br />&nbsp;*/&nbsp;<br />&nbsp;private ArrayList listOfWords;&nbsp;<br />/**&nbsp;<br />&nbsp;* @gwt.typeArgs &lt;java.util.Date&gt;&nbsp;<br />&nbsp;*/&nbsp;<br />&nbsp;private Vector listOfDates;&nbsp;</span></p>
</ul>
</ul>
<p>We can also implement this for return types and parameters.&nbsp;</p>
<p><span class=TextBoldBlue><strong>Exception Handling in GWT</strong>&nbsp;</span></p>
<p>Remote Procedure Calls open up the possibilities of errors and exceptions. Errors may be due to various issues such as Network error, Server related issues, Server-Client call transactions etc. GWT allows us to handle exceptions easily and efficiently. Any RPC related exception can be categorized&nbsp;&nbsp; into two types.</p>
<p>Checked Exceptions</p>
<p>Unexpected Exceptions</p>
<p><strong class=TextBoldBlue>Common or Checked Exceptions</strong>&nbsp;</p>
<p>When a Service interface method is implemented there are many possibilities of exceptions being thrown and in order to handle that throw, declarations are added. The throw indicates that an exception may be thrown back during the implementation. AsyncCallback.onFailure(Throwable)is the primary interface a caller must implement to receive a response from a remote procedure call. If an RPC is successful, then onSuccess(Object) is called, otherwise onFailure(Throwable) is called. The asynchronous method always takes an AsyncCallback as its last parameter.&nbsp;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.g.: <span class=textCode>Animal[] getAnimals(String databaseName) throws AnimalException, DbException;&nbsp;</span></p>
<p>Its asynchronous counterpart method is declared as:&nbsp;</p>
<ul>
<p class=textCode>void getAnimals(String databaseName, AsyncCallback callback);&nbsp; </p>
</ul>
<p>Note that the throws declaration is not repeated in the Async version.&nbsp;</p>
<p>A typical AsyncCallback call might look like this:</p>
<ul>
<p><span class=textCode>service.getAnimals(dbName, new AsyncCallback() {&nbsp;<br />&nbsp;&nbsp; public void onSuccess(Object result) {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; // Downcasting to the known return type.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Animal[] animals = (Animal[]) result;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; controller.processAnimals(animals);&nbsp;<br />&nbsp;&nbsp; }&nbsp;<br />&nbsp;<br />&nbsp;&nbsp; public void onFailure(Throwable caught) {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw caught;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; } catch (InvocationException e) {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Call terminated in a adhoc way&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; } catch (AnimalException e) {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // one of the &#8216;throws&#8217; from the original method&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; } catch (DbException e) {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // one of the &#8216;throws&#8217; from the original method&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; } catch (Throwable e) {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // last resort &#8212; a very unexpected exception&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;<br />&nbsp;&nbsp; }&nbsp;<br />});&nbsp;<br />&nbsp;</span></p>
</ul>
<p><span class=TextBoldBlue><strong>Ad-hoc Exceptions</strong>&nbsp;</span></p>
<p>If an Exception occurs &#8216;ad-hoc&#8217; then it is termed an Unchecked Exception. There are many reasons why such exceptions might occur, they will be mainly due to machine and server related issues. Network breakdown, DNS error, HTTP process error etc. &nbsp;</p>
<p>An InvocationException is passed to the implementation of AsyncCallback.onFailure (Throwable). This class is called <em>Invocation</em>Exception because the problem was with the invocation attempt itself rather than with the service implementation. A NullPointerException might also lead to this, since that is ad-hoc.</p>
<p>There are two types of InvocationException:</p>
<div align=left>
<ul>
<table cellSpacing=0 width=0 border=2>
<tbody>
<tr vAlign=top>
<td width="44%" bgColor=#d9d9d9>InvocationException(String)</td>
<td width="55%" bgColor=#d9d9d9>Constructs an exception with the given description.</td>
</tr>
<tr vAlign=top>
<td bgColor=#d9d9d9>InvocationException(String, Throwable)</td>
<td bgColor=#d9d9d9>Constructs an exception with the given description and cause.</td>
</tr>
</tbody>
</table>
</ul>
</div>
<p>&nbsp;
<p>GWT also allows us to implement almost all types of exceptions that are in Java.&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; </p>
<p><strong class=TextBoldBlue>Asynchronous Calls</strong></p>
<p>An asynchronous call comes into play when we need parallelism in our applications.</p>
<p>For example if we have a page which contains a huge table containing many widgets and we need to fetch data from the Server for the table and at the same time as we need to construct all the widgets that are required building the table itself is time consuming and fetching the data adds to the load. If we implement Asynchronous calls by the time the table is constructed with widgets, the data can be fetched from the Server Asynchronously, this will reduce the load time and at the same time double the efficiency.<br />&nbsp;<br />In case of Asynchronous calls, a common problem is blocking, but this can be managed with the concept of Inner classes.&nbsp;</p>
<p><strong>RPC Example:</strong></p>
<p>1. Create a new Eclipse GWT project named MyFirstRPC using the projectCreator and applicationCreator. Set the name of the application class to com.test.MyFirstRPC.client.MyFirstRPC.&nbsp;</p>
<p>2. If you are comfortable you can build the Project as it is or you can use any standard IDE like Eclipse.&nbsp;</p>
<p>3. Create a Java file and name it as NumsService.java in the com.test.MyFirstRPC.client package. &nbsp;</p>
<p>Define a NumsService interface with one method that verifies if a number is an even. It takes an integer as a parameter and returns a Boolean value upon verification: &nbsp;</p>
<p class=textCode>public interface NumsService extends RemoteService </p>
<p class=textCode>{ </p>
<p class=textCode>public boolean isEven(int numberToVerify); </p>
<p><span class=textCode>}&nbsp;</span></p>
<p>4.Create a new Java file named NumsServiceAsync.java in the com.test.MyFirstRPC.client package. Define a NumsServiceAsync interface:</p>
<p class=textCode>public interface NumsServiceAsync </p>
<p class=textCode>{ </p>
<p class=textCode>public void isEven(inr numberToVerify, AsyncCallbackcallback);</p>
<p><span class=textCode>}&nbsp;</span><br />&nbsp;</p>
<p>5.Create a new Java file, named NumsServiceImpl.java in the com.test.MyFirstRPC.<br />
server package. Define a NumsServiceImpl class that extends RemoteServiceServlet and implements the previously created NumsService interface. Add functionality to this class to verify if the provided number is an even number.</p>
<p class=textCode>public class NumsServiceImpl extends RemoteServiceServlet </p>
<p class=textCode>implements NumsService </p>
<p class=textCode>{ </p>
<p class=textCode>private static final long serialVersionUID = -8620968747002510678L; </p>
<p class=textCode>public boolean isEven(int numberToVerify) </p>
<p class=textCode>{ </p>
<p class=textCode>boolean numIs = false; </p>
<p class=textCode>if ( (numberToVerify%2)==0) </p>
<p class=textCode>{ </p>
<p class=textCode>numIs = true; </p>
<p class=textCode>break; </p>
<p class=textCode>} </p>
<p class=textCode>return numIs; </p>
<p class=textCode>}</p>
<p><span class=textCode>}&nbsp;</span><br />&nbsp;</p>
<p>//break//</p>
<p>6. Create the client in a new file named NumsClient.java in the com.test.MyFirstRPC.client package that extends the EntryPoint class. </p>
<p class=textCode>public class NumsClient implements EntryPoint </p>
<p class=textCode>{ </p>
<p class=textCode>}</p>
<p>7. Add an onModuleLoad() method to this new class, and create a text box. </p>
<p class=textCode>public void onModuleLoad() </p>
<p class=textCode>{ </p>
<p class=textCode>final TextBox IsEvenTxt = new TextBox(); </p>
<p><span class=textCode>}&nbsp;</span></p>
<p>8. Instantiate the NumsService and store it in a variable in the onModuleLoad()method. </p>
<p class=textCode>final NumsServiceAsync NumsService = (NumsServiceAsync) GWT </p>
<p class=textCode>GWT.create(NumsService.class); </p>
<p class=textCode>ServiceDefTarget endpoint = (ServiceDefTarget) NumsService; </p>
<p class=textCode>endpoint.setServiceEntryPoint(GWT.getModuleBaseURL()+&#8221;Nums&#8221;);</p>
<p>9. Create a new button, and add an event handler to listen for clicks on the button. In the handler, invoke the NumsService using the text typed into the text box as the input parameter to the service. Display the result in an alert dialog. &nbsp;</p>
<ul>
<p><span class=textCode>final Button checkNum=new Button(&#8220;Is this an Even number?&#8221;, </span></p>
</ul>
<ul>
<p><span class=textCode>new ClickListener()) </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>public void onClick(Widget sender) </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>AsyncCallback callback = new AsyncCallback() </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>public void onSuccess(Object result) </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>if(((Boolean) result).booleanValue()) </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>Window.alert(&#8220;Yes, &#8220;+ IsEvenTxt.getText() </span></p>
</ul>
<ul>
<p><span class=textCode>+ &#8220;&#8216; is a Even number.&#8221;); </span></p>
</ul>
<ul>
<p><span class=textCode>} </span></p>
</ul>
<ul>
<p><span class=textCode>else </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>Window.alert(&#8220;No, &#8220;+ IsEvenTxt.getText() </span></p>
</ul>
<ul>
<p><span class=textCode>+ &#8220;&#8216; is not a Even number.&#8221;); </span></p>
</ul>
<ul>
<p><span class=textCode>} </span></p>
</ul>
<ul>
<p><span class=textCode>} </span></p>
</ul>
<ul>
<p><span class=textCode>public void onFailure(Throwable caught) </span></p>
</ul>
<ul>
<p><span class=textCode>{ </span></p>
</ul>
<ul>
<p><span class=textCode>Window.alert(&#8220;Error while calling the Nums </span></p>
</ul>
<ul>
<p><span class=textCode>Service.&#8221;); </span></p>
</ul>
<ul>
<p><span class=textCode>} </span></p>
</ul>
<ul>
<p><span class=textCode>}; </span></p>
</ul>
<ul>
<p><span class=textCode>NumsService.isIsEvenTxt(Integer </span></p>
</ul>
<ul>
<p><span class=textCode>parseInt(IsEvenTxt.getText()), callback); </span></p>
</ul>
<ul>
<p><span class=textCode>} </span></p>
</ul>
<ul>
<p><span class=textCode>});&nbsp;</span></p>
</ul>
<p>10. Add the following entry to the application&#8217;s module.xml file in order for the client to find this service. </p>
<p class=textCode>&lt;servlet path=&#8221;/Nums&#8221; class= </p>
<p><span class=textCode>&#8220;com.test.MyFirstRPC.server.NumsServiceImpl&#8221;/&gt;&nbsp;</span></p>
<p>When you execute the app, you will get the result like this</p>
<p>&nbsp;<img height=500 src="http://www.ajaxmatters.com/images/rpc2.JPG" width=661><br />&nbsp;</p>
<p><strong>Conclusion:</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Google Web Toolkit has made RPC really simple and at the same time with the implementation of Asynchronous Calls the transactions occurs parallely and dynamically giving the User a complete AJAX experience and the developer a easy life to architect the application.&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/introduction-to-gwt-remote-procedure-calls-rpc-with-example-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an ASP.NET AJAX-Enabled Grid using ICallbackEventHandler (Part 1)</title>
		<link>http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-1/</link>
		<comments>http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-1/#comments</comments>
		<pubDate>Sun, 14 May 2006 23:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://ajaxmatters.com.php5-10.dfw1-2.websitetestlink.com/?p=7</guid>
		<description><![CDATA[This article details the development of an ASP.NET AJAX-enabled grid using ICallbackEventHandler, with operations which include sorting, paging and page length change. I will work through the code in sequence, but it may help to download to the entire code &#8230; <a href="http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This article details the development of an <a href="http://www.aspnet101.com">ASP.NET</a> AJAX-enabled grid using ICallbackEventHandler, with operations which include sorting, paging and page length change. I will work through the code in sequence, but it may help to download to the entire code sample <a href="http://www.ajaxmatters.com/code/callback_grig.zip">here</a></p>
<p>The basic features of the gird are as follows (All operations are asynchronous)</p>
<ol type="1">
<li>Sort in ascending or in descending order by clicking on the arrows next to column name.</li>
<li>Change current page.</li>
<li>Change page length.</li>
</ol>
<p>In this example we will use one of the most powerful features of ASP.Net &#8211; RenderControl.</p>
<p>Using this method we are able to access the HTML of a control. To do this we will have to also use HtmlTextWriter and  StringWriter as follows</p>
<p>e.g.</p>
<p class="textCode">using (StringWriter sw = new StringWriter())</p>
<p class="textCode">{</p>
<p class="textCode">HtmlTextWriter htw = new HtmlTextWriter(sw);</p>
<p class="textCode">_grid.RenderControl(htw);</p>
<p class="textCode">htw.Flush();</p>
<p class="textCode">string result = sw.ToString();</p>
<p class="textCode">}</p>
<p>The <em>result</em> string will contain the HTML format of the grid control. We will now convert the grid control to HTML after binding the data.</p>
<p>We will start by developing the UI and code in following steps:</p>
<ol type="1">
<li>Enter the following code in the &lt;form&gt; tag of the page to create a GridView and a Dropdownlist.</li>
</ol>
<p><span class="textCode"> &lt;div id=&#8221;Gridview&#8221; &gt;</span></p>
<p class="textCode">&lt;asp:GridView EnableViewState=&#8221;false&#8221; runat=&#8221;server&#8221; id=&#8221;_grid&#8221; OnRowDataBound=&#8221;_grid_RowDataBound&#8221; AllowPaging=&#8221;True&#8221; &gt;</p>
<p class="textCode">&lt;/asp:GridView&gt;</p>
<p class="textCode">&lt;br /&gt;</p>
<p class="textCode">&lt;/div&gt; Change page length to &#8211;</p>
<p class="textCode">&lt;asp:DropDownList ID=&#8221;ddl&#8221; runat=&#8221;server&#8221;&gt;</p>
<p class="textCode">&lt;/asp:DropDownList&gt;</p>
<p>Please note that RowDataBound event of the grid has been activated.</p>
<ol type="1">
<li>Now we will create a DataTable to be used as DataSource for the GridView.</li>
</ol>
<p><span class="textCode">public DataTable _sampleData</span></p>
<p class="textCode">{</p>
<p class="textCode">get {</p>
<p class="textCode">DataTable dt = (DataTable)ViewState["DataTable"];</p>
<p class="textCode">if(dt == null)</p>
<p class="textCode">{</p>
<p class="textCode">dt = new DataTable();</p>
<p class="textCode">dt.Columns.Add(new DataColumn(&#8220;Contact Name&#8221;,typeof(string)));</p>
<p class="textCode">dt.Columns.Add(new DataColumn(&#8220;Company Name&#8221;, typeof(string)));</p>
<p class="textCode">dt.Columns.Add(new DataColumn(&#8220;City&#8221;, typeof(string)));</p>
<p class="textCode">dt.Columns.Add(new DataColumn(&#8220;Country&#8221;, typeof(string)));</p>
<p class="textCode">dt.Rows.Add(new object[] { &#8220;Maria Anders&#8221; ,&#8221;Alfreds Futterkiste&#8221;,&#8221;Berlin&#8221;,&#8221;Germany&#8221;});</p>
<p class="textCode">dt.Rows.Add(new object[] { &#8220;Ana Trujillo&#8221; ,&#8221;Emparedados y helados &#8220;,&#8221;México D.F.&#8221;,&#8221;Mexico&#8221;});</p>
<p class="textCode">dt.Rows.Add(new object[] { &#8220;Antonio Moreno&#8221;, &#8220;Antonio Moreno Taquería&#8221;, &#8220;México D.F.&#8221;,&#8221;Mexico&#8221; });</p>
<p class="textCode">ViewState["DataTable"] = dt;</p>
<p class="textCode">}</p>
<p class="textCode">return dt;</p>
<p class="textCode">}</p>
<p>In the above code we have used ViewState instead of a Session variable.</p>
<p>i.e.       <span class="textCode">ViewState["DataTable"] = dt;</span></p>
<p>This will preserve the table for that page. Using Session variable the table would be available throughout the website, but using ViewState the table will only be available for that page.</p>
<p>To bind this table to the GridView we simply use <span class="textCode">_grid.DataSource = _sampleData;</span></p>
<ol type="1">
<li>We will write following four functions for grid operations</li>
</ol>
<ul type="DISC">
<li>
<ol type="1">
<li>We need four functions for ICallBackEventHandler &#8211; two are JavaScript functions (one for Callback to server and another for displaying the response data from server). And two are Server side functions (<strong>RaiseCallbackEvent(</strong><strong>string</strong><strong> eventArgument) and GetCallbackResult()</strong>)</li>
</ol>
<ol type="a">
<li>Action .</li>
</ol>
<ol type="a">
<li>Page index of the Grid.</li>
</ol>
<ol type="a">
<li>Page size from the dropdown list (i.e. id is ‘ddl’).</li>
</ol>
<ol type="1">
<li>Add following code
<p><span class="textCode">protected void Page_Load(object sender, EventArgs e) </span></li>
</ol>
<ol type="1">
<li>Now we will write code in the <strong>RowDataBound</strong> event of the GridView &#8211; i.e. in protected void _grid_RowDataBound(object sender, GridViewRowEventArgs e)</li>
</ol>
</li>
<p><span class="textCode">private void sortGrid(string Argument , string pageLength) </span></p>
<p class="textCode">{</p>
<p class="textCode">DataView dv = _sampleData.DefaultView;</p>
<p class="textCode">result = &#8220;&#8221;;</p>
<p class="textCode">dv.Sort = Argument;</p>
<p class="textCode">_grid.DataSource = dv;</p>
<p class="textCode">_grid.PageSize = Convert.ToInt16(pageLength);</p>
<p class="textCode">_grid.DataBind();</p>
<p class="textCode">renderGrid(_grid);</p>
<p class="textCode">}</p>
<p class="textCode">private void changePage(string Argument , string       pageLength)</p>
<p class="textCode">{</p>
<p class="textCode">result = &#8220;&#8221;;</p>
<p class="textCode">_grid.DataSource = _sampleData;</p>
<p class="textCode">_grid.PageSize = Convert.ToInt16(pageLength);</p>
<p class="textCode">_grid.PageIndex = Convert.ToInt16(Argument);</p>
<p class="textCode">_grid.DataBind();</p>
<p class="textCode">renderGrid(_grid);</p>
<p class="textCode">}</p>
<p class="textCode">private void changePageLength(string Argument,  string pageLength)</p>
<p class="textCode">{</p>
<p class="textCode">result = &#8220;&#8221;;</p>
<p class="textCode">_grid.DataSource = _sampleData;</p>
<p class="textCode">_grid.PageSize = Convert.ToInt16(Argument);</p>
<p class="textCode">_grid.DataBind();</p>
<p class="textCode">renderGrid(_grid);</p>
<p class="textCode">//pageLength is not used</p>
<p class="textCode">}</p>
<p class="textCode">private void renderGrid(GridView _grid)</p>
<p class="textCode">{</p>
<p class="textCode">using (StringWriter sw = new StringWriter())</p>
<p class="textCode">{</p>
<p class="textCode">HtmlTextWriter htw = new HtmlTextWriter(sw);</p>
<p class="textCode">_grid.RenderControl(htw);</p>
<p class="textCode">htw.Flush();</p>
<p>lass=textCode&gt;            result = sw.ToString();</p>
<p class="textCode">}</p>
<p class="textCode">}</p>
<p>The names of the above functions indicates their functionality, the second parameter of the first three functions is “<strong>pageLength</strong>”<strong> </strong>this is the value of the dropdown list</p>
<p>JavaScript  functions are as follows:</p>
<p class="textCode">function UpdateGrid(args)</p>
<p class="textCode">{</p>
<p class="textCode">args = args + &#8220;$&#8221; + window.document.getElementById(&#8216;ddl&#8217;).value;</p>
<p class="textCode">&lt;%= ClientScript.GetCallbackEventReference(this,&#8221;args&#8221;, &#8220;ShowResult&#8221;, null) %&gt;</p>
<p class="textCode">}</p>
<p>After rendering, if we open the source of the page; above function will appear as</p>
<p><strong>function UpdateGrid(args)</strong></p>
<p><strong> {</strong></p>
<p><strong>args = args + &#8220;$&#8221; +            window.document.getElementById(&#8216;ddl&#8217;).value;</strong></p>
<p><strong> WebForm_DoCallback(&#8216;__Page&#8217;,args,ShowResult,null,null,false)</strong></p>
<p><strong> }</strong></p>
<p>When we want to do a Callback, we are actually firing an event which is related to the <strong>Webform. </strong>Therefore the UpdateGrid(args) function needs to be placed in the &lt;form&gt; tag, otherwise we will get a JavaScript error.</p>
<p>We register this function by using <strong>Page.ClientScript.RegisterClientScriptBlock </strong>so the function will appear in &lt;form&gt;&lt;/form&gt; tag only.</p>
<p><span class="textCode">function ShowResult(eventArgument,context) </span></p>
<p class="textCode">{</p>
<p class="textCode">window.document.getElementById(&#8216;Gridview&#8217;).innerHTML = eventArgument;</p>
<p class="textCode">}</p>
<p>This function will be fired after server sends a response back to client, thus this function will handle the server response. We have simply put the response as innerHTML of the Div tag. The innerHTML contains the HTML of the updated grid.</p>
<p>The server-Side functions are as follows</p>
<p><span class="textCode">public string GetCallbackResult() </span></p>
<p class="textCode">{</p>
<p class="textCode">return result;</p>
<p class="textCode">}</p>
<p>This function simply returns the result which we have put as innerHTML in the <strong>ShowResult</strong> function.</p>
<p><span class="textCode">public void RaiseCallbackEvent(string eventArgument) </span></p>
<p class="textCode">{</p>
<p class="textCode">string[] args = eventArgument.Split(&#8216;$&#8217;);</p>
<p class="textCode">if (args[0] == &#8220;sort&#8221;) { sortGrid(args[1], args[2]); }</p>
<p class="textCode">else if (args[0] == &#8220;changePage&#8221;) { changePage(args[1], args[2]); }</p>
<p class="textCode">else if (args[0] == &#8220;changePageLength&#8221;) { changePageLength(args[1], args[2]); }</p>
<p class="textCode">}</p>
<p>In this function the <strong>eventArgument </strong>will appear as “changePage$1$10” or “sort$1$10” or  “changePageLength$1$10” or “sort$Contact Name Asc$10” or  “sort$Contact Name Desc$10” in the rendered page</p>
<p>If we split this on “$”, we will get</p>
<p>(In changePageLength we don’t need args[2]; I have kept is just to simplify the code)</p>
<p>In <strong>RaiseCallbackEvent</strong> we have called the function which we have decleared in <strong>POINT 3,</strong> each function in point 3 will do the respective action and return a HTML string of the Grid.</p>
<p class="textCode">if (!IsPostBack)</p>
<p class="textCode">{</p>
<p class="textCode">_grid.DataSource = _sampleData;</p>
<p class="textCode">_grid.DataBind();</p>
<p class="textCode">ddl.Items.Add(&#8220;10&#8243;);</p>
<p class="textCode">ddl.Items.Add(&#8220;20&#8243;);</p>
<p class="textCode">ddl.Items.Add(&#8220;30&#8243;);</p>
<p class="textCode">ddl.Attributes.Add(&#8220;onchange&#8221;, &#8220;javascript:UpdateGrid(&#8216;changePageLength$&#8217; + this.value);&#8221;);</p>
<p class="textCode">}</p>
<p>[At this point if we compile the code we will able to chage the page  length ]</p>
<p>//break//</p>
<p>For adding the columnwise sorting functionality in grid, we will modify columnheader row of the GridView. <span class="textCode"><br />
</span></p>
<p class="textCode">if (e.Row.RowType == DataControlRowType.Header)</p>
<p class="textCode">{</p>
<p class="textCode">for (int i = 0; i &lt; e.Row.Cells.Count; i++)</p>
<p class="textCode">{</p>
<p class="textCode">e.Row.Cells[i].Text = string.Format(&#8220;{0}&lt;img alt=&#8221;Ascending&#8221; src=&#8221;Images/up.jpg&#8221; onclick=&#8221;UpdateGrid(&#8216;sort${0} Asc&#8217;)&#8221;; /&gt;&lt;img alt=&#8221;Descending&#8221; src=&#8221;Images/down.jpg&#8221; onclick=&#8221;UpdateGrid(&#8216;sort${0} desc&#8217;) &#8220;; /&gt;&#8221;, e.Row.Cells[i].Text);</p>
<p class="textCode">}</p>
<p class="textCode">}</p>
<p>We have added up and down images and an onclick event of either of them will call the <strong>UpdateGrid</strong> function (Ref. Point 4) for sorting  Ascending and Descending order repectively. [At this point you can complie the code and the grid will be sortable].</p>
<p>After this we will modify the Pager row in such a way that we can use it to change the page index of the grid using UpdateGrid function.(Ref. point 4 public void RaiseCallbackEvent)</p>
<p class="textCode">else if (e.Row.RowType == DataControlRowType.Pager)</p>
<p class="textCode">{</p>
<p class="textCode">GridView gdv = (GridView)sender;</p>
<p class="textCode">int _pageCount = gdv.PageCount;</p>
<p class="textCode">e.Row.Cells[0].Text = &#8220;&#8221;;</p>
<p class="textCode">for (int i = 0; i &lt; _pageCount; i++)</p>
<p class="textCode">{</p>
<p class="textCode">HyperLink hyp = new HyperLink();</p>
<p class="textCode">hyp.Text = i.ToString() + &#8220;&amp;nbsp;&#8221;;</p>
<p class="textCode">hyp.Attributes.Add(&#8220;href&#8221;, &#8220;javascript:UpdateGrid(&#8216;changePage$&#8221; + i + &#8220;&#8216;);&#8221;);</p>
<p class="textCode">e.Row.Cells[0].Controls.Add(hyp);</p>
<p class="t&lt;br">
<p>extCode&gt;         Label l = new Label();</p>
<p class="textCode">l.Text = &#8220;&amp;nbsp;&#8221;;</p>
<p class="textCode">e.Row.Cells[0].Controls.Add(l);</p>
<p class="textCode">hyp = null;</p>
<p class="textCode">}</p>
<p><span class="textCode"> } </span></p>
<p>_pageCount contains the pagecount of the GridView. We have to display pages as Numbers so we used a HyperLink and a Label to add space after each page number.</p>
<p>Finally, we can set EnableViewState=&#8221;false&#8221; this will not affect the functionality but the extra code of the ViewState will not come on client side which leads to lighter page.</p>
<p>The entire code for the sample can be downloaded <a href="http://www.ajaxmatters.com/code/callback_grig.zip">here</a></ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxmatters.com/2006/05/creating-an-ajax-enabled-grid-using-icallbackeventhandler-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

