<?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>All Free Tech &#187; Ajax</title>
	<atom:link href="http://www.allfreetech.com/category/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://www.allfreetech.com</link>
	<description>For developers</description>
	<lastBuildDate>Tue, 27 Jul 2010 13:58:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ajax-based Login Control Without Any Standard Database</title>
		<link>http://www.allfreetech.com/ajax/ajax-based-login-control-without-any-standard-database-868.html</link>
		<comments>http://www.allfreetech.com/ajax/ajax-based-login-control-without-any-standard-database-868.html#comments</comments>
		<pubDate>Sun, 18 Jul 2010 11:06:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Ajaxbased]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Standard]]></category>
		<category><![CDATA[Without]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=868</guid>
		<description><![CDATA[Introduction: In this tutorial I am going to base a simple login control on AJAX. All login control needs a database that stores all user profiles, such as passwords. Server-side script uses the database from user given string to compare and match shows, errors or redirects to relevant pages, etc. However, the proposed technique is [...]]]></description>
			<content:encoded><![CDATA[<p>Introduction: In this tutorial I am going to base a simple login control on AJAX. All login control needs a database that stores all user profiles, such as passwords. Server-side script uses the database from user given string to compare and match shows, errors or redirects to relevant pages, etc. However, the proposed technique is no standard database such as Access, SQL is required, etc. It only takes a native XML Flat / text database, to implement the minimum complexity in practice.&nbsp;</p>
<p>I was looking for this kind of simple log-in approach and, finally, came the thought, however, the Asynchronous JavaScript and XML technology (in short AJAX) . On many occasions, the establishment of an external database is cumbersome and not worthy in terms of minimal customs. The proposed Login control, but will help you all the load, and compatibility issues to be removed. To be clear, conventional and standard database application, a database server, the authentication and authorization required before the creation of a database, database string to be used in the script, the platform-specific and is awkward for me always. To get rid of all the costs and efforts, the proposed approach uses a simple flat database tables and read the database with (AJAX) to control a pretty login.&nbsp;</p>
<p>
	Keep reading</p>
<p>! <br />
	&nbsp;</p>
<p>Big Picture: The following figure shows the AJAX-based login control display. User can enter his password into the text field. The simplicity, I have all the names of the States United States as passwords. If the user specified string games with one of the passwords, make the &quot;search&quot; button appears. In other words, the user&#39;s desired page by clicking on this button will be forwarded. <br />
	&nbsp;</p>
<p>In case the user&#39;s input string is not a pre-fix match of the passwords, the color of the text box will automatically be yellow. It tells the user not in this direction and try to delete some of the characters try again. </p>
<p>
	&nbsp;</p>
<p>Necessary files: we need four files for this login control <br />
	&nbsp;</p>
<p>i) script. html <br />
	&nbsp;</p>
<p>ii) script. CSS <br />
	&nbsp;</p>
<p>iii) script. js <br />
	&nbsp;</p>
<p>iv) script. xml <br />
	&nbsp;</p>
<p>the HTML and CSS file corresponds to the content and design to show, above all, at various components. Note that the &quot;query&quot; Submit &quot;button is kept hidden from visibility. It will only be displayed if the user string with one of the passwords stored in the XML file matches. <br />
	&nbsp;</p>
<p>JavaScript AJAX file controls the connectivity and read the password on the fly. As soon as user presses a letter on the text field, the function works for any game or disproportionate to review and act accordingly. <br />
	&nbsp;</p>
<p>hold a single character fills the function of all passwords in a hidden &quot;popoups&quot; (which is actually not a pop!) HTML component. The function is true then the string with the user string. If the pop-ups component is empty, there is the user string is not a prefix of one of the passwords and makes the text box yellow. <br />
	&nbsp;</p>
<p>present but in the event of agreement between the two strings, the button will be displayed. User can now click directly requested by his side. <br />
	&nbsp;</p>
<p><script type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ajax/ajax-based-login-control-without-any-standard-database-868.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create an ASP.NET Modal Popup Login</title>
		<link>http://www.allfreetech.com/ajax/how-to-create-an-asp-net-modal-popup-login-158.html</link>
		<comments>http://www.allfreetech.com/ajax/how-to-create-an-asp-net-modal-popup-login-158.html#comments</comments>
		<pubDate>Fri, 29 Jan 2010 14:12:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=158</guid>
		<description><![CDATA[In this article, Yi demonstrates how to create a modal popup login page in ASP.NET. By using Login controls, AJAX Extensions, and the AJAX Control Toolkit, you can easily accomplish this task without much coding. The demo project is based on Visual Web Developer Express 2008 and the .NET Framework 3.5. It also assumes you [...]]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">In this article, Yi demonstrates how to create a modal popup login page in ASP.NET. By using Login controls, AJAX Extensions, and the AJAX Control Toolkit, you can easily accomplish this task without much coding. The demo project is based on Visual Web Developer Express 2008 and the .NET Framework 3.5. It also assumes you have installed the AJAX Control Toolkit.<span id="more-158"></span></span></p>
<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span id="intellitTxt"><a class="pageTitle" id="#Page1" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Introduction</a></span></span></p>
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">In this article, I will demonstrate how to create a modal popup login page in&nbsp;<a class="kLink" href="http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all#" id="KonaLink0" style="color: blue !important; background-color: transparent !important; border-bottom-style: none !important; text-decoration: underline !important; cursor: pointer; font-family: verdana; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-top-style: none !important; border-right-style: none !important; border-left-style: none !important; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; border-left-color: transparent !important; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; text-transform: none !important; display: inline !important; font-variant: normal; top: 0px; right: 0px; bottom: 0px; left: 0px; position: static; background-position: initial initial !important; background-repeat: initial initial !important; " target="undefined"><font color="blue" style="color: blue !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; "><span class="kLink" style="border-top-width: 0px !important; border-top-style: none !important; border-top-color: initial !important; border-left-width: 0px !important; border-left-style: none !important; border-left-color: initial !important; border-right-width: 0px !important; border-right-style: none !important; border-right-color: initial !important; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: initial; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 1px !important; padding-left: 0px !important; color: blue !important; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; width: auto !important; float: none !important; display: inline !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; background-position: initial initial; background-repeat: initial initial; ">ASP.NET</span></font></a>. By using Login controls, AJAX Extensions and Toolkit, you can easily accomplish this task without much coding.</span></div>
<div class="KonaBody">
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">The demo project is based on Visual Web&nbsp;<a class="kLink" href="http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all#" id="KonaLink1" style="color: blue !important; background-color: transparent !important; border-bottom-style: none !important; text-decoration: underline !important; cursor: pointer; font-family: verdana; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-top-style: none !important; border-right-style: none !important; border-left-style: none !important; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; border-left-color: transparent !important; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; text-transform: none !important; display: inline !important; font-variant: normal; top: 0px; right: 0px; bottom: 0px; left: 0px; position: static; background-position: initial initial !important; background-repeat: initial initial !important; " target="undefined"><font color="blue" style="color: blue !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; "><span class="kLink" style="border-top-width: 0px !important; border-top-style: none !important; border-top-color: initial !important; border-left-width: 0px !important; border-left-style: none !important; border-left-color: initial !important; border-right-width: 0px !important; border-right-style: none !important; border-right-color: initial !important; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: blue; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 1px !important; padding-left: 0px !important; color: blue !important; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; width: auto !important; float: none !important; display: inline !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; background-position: initial initial; background-repeat: initial initial; ">Developer</span></font></a></span>&nbsp;Express 2008 and .NET Framework 3.5. It also assumes you have installed AJAX Toolkit. You can&nbsp;<a class="kLink" href="http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all#" id="KonaLink2" style="color: blue !important; background-color: transparent !important; border-bottom-style: none !important; text-decoration: underline !important; cursor: pointer; font-family: verdana; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-top-style: none !important; border-right-style: none !important; border-left-style: none !important; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; border-left-color: transparent !important; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; text-transform: none !important; display: inline !important; font-variant: normal; top: 0px; right: 0px; bottom: 0px; left: 0px; position: static; background-position: initial initial !important; background-repeat: initial initial !important; " target="undefined"><font color="blue" style="color: blue !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; "><span class="kLink" style="border-top-width: 0px !important; border-top-style: none !important; border-top-color: initial !important; border-left-width: 0px !important; border-left-style: none !important; border-left-color: initial !important; border-right-width: 0px !important; border-right-style: none !important; border-right-color: initial !important; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: initial; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 1px !important; padding-left: 0px !important; color: blue !important; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; width: auto !important; float: none !important; display: inline !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; background-position: initial initial; background-repeat: initial initial; ">download</span></font></a>&nbsp;source code from here.</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">[<span class="MsoHyperlink"><a href="http://authors.aspalliance.com/YLiu/ModalPopupLogin.zip" style="color: rgb(144, 11, 9); background-color: transparent; ">Download Sample</a></span>]</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 1 &ndash; Login page with modal popup</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img border="0" height="343" id="Picture 7" src="http://aspalliance.com/ArticleFiles/1882/image001.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="432" /></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Key features of this project include:</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Place login part in MasterPage and content in ContentPage.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Utilize Login, LoginStatus controls.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Use ModalPopupExtender and UpdatePanel to avoid postback.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Take advantage of Forms Authentication.</p>
</div>
<p><span id="intellitTxt"><a class="pageTitle" id="#Page2" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Walkthrough</a></span></p>
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="font-size: 12px; ">Let&rsquo;s get started by creating a new website, and then add a MasterPage. Based on the MasterPage, add a ContentPage and rename it to Login.aspx. You should have files similar to Listing 2 by then.</span></div>
<div class="KonaBody">
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 2 -&nbsp;<a class="kLink" href="http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all#" id="KonaLink3" style="color: blue !important; background-color: transparent !important; border-bottom-style: none !important; text-decoration: underline !important; cursor: pointer; font-family: verdana; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-top-style: none !important; border-right-style: none !important; border-left-style: none !important; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; border-left-color: transparent !important; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; text-transform: none !important; display: inline !important; font-variant: normal; top: 0px; right: 0px; bottom: 0px; left: 0px; position: static; background-position: initial initial !important; background-repeat: initial initial !important; " target="undefined"><font color="blue" style="color: blue !important; font-family: Verdana, sans-serif; font-weight: bold; font-size: 13px; position: static; "><span class="kLink" style="border-top-width: 0px !important; border-top-style: none !important; border-top-color: initial !important; border-left-width: 0px !important; border-left-style: none !important; border-left-color: initial !important; border-right-width: 0px !important; border-right-style: none !important; border-right-color: initial !important; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: initial; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 1px !important; padding-left: 0px !important; color: blue !important; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; width: auto !important; float: none !important; display: inline !important; font-family: Verdana, sans-serif; font-weight: bold; font-size: 13px; position: static; background-position: initial initial; background-repeat: initial initial; ">Files</span></font></a>&nbsp;created for the project</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img border="0" height="260" id="Picture 4" src="http://aspalliance.com/ArticleFiles/1882/image002.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="296" /></p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">web.config</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">To restrict anonymous access and allow only authenticated user, we need to add a few lines in web.config file. Note that the authentication mode is set to Forms.</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">authentication</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">mode</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Forms&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">authorization</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">deny</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">users</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;?&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">allow</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">users</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;*&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">authorization</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></pre>
</div>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">MasterPage.master</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Now go to MasterPage.master and we will do the most important work here. Follow steps below.</p>
<p class="MsoListNumber" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; ">1.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>Add a ScriptManager on MasterPage, which enables the website to run AJAX.</p>
<p class="MsoListNumber" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; ">2.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>On the same page, create a LoginStatus and place it right above ContentPlaceHolder.</p>
<p class="MsoListNumber" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; ">3.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>Right click the LoginStatus and select Add Extender. Choose the ModalPopupExtender.</p>
<p class="MsoListNumber" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; ">4.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>Right below the ContentPlaceHolder, create a Panel. Within the ContentPlaceHolder, add a UpdatePanel.</p>
<p class="MsoListNumber" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; ">5.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>At last, put a Login control in the UpdatePanel.</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">In design view, you should get a page similar to Listing 3.</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 3 &#8211; design view of Login.aspx</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img border="0" height="206" id="Picture 10" src="http://aspalliance.com/ArticleFiles/1882/image003.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="272" /></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">However, to make things work we have to add a few more lines. First, let&rsquo;s add two styles in the markup; we will use them very soon. The first style is for the transparent background on top of regular content. Second one tells how the small popup dialog looks like.</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">style</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">type</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;text/css&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.modalBackground&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:&nbsp;Gray;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter:&nbsp;alpha(opacity=30);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity:&nbsp;0.3;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.modalPopup&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width:&nbsp;250px;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height:&nbsp;150px;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:&nbsp;#076DAB;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color:&nbsp;#FFFFFF;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border-color:&nbsp;#000000;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border-width:&nbsp;1px;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border-style:&nbsp;solid;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text-align:&nbsp;center;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor:&nbsp;move;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-size:&nbsp;medium;}
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">style</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Next, go to ModalPopupExtender&rsquo;s properties: set the style for BackgroundCssClass and assign the panel ID to PopupControlID. As a result, the extender markup should look like:</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">cc1:ModalPopupExtender</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;LoginStatus1_ModalPopupExtender&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">DynamicServicePath</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;&quot;</span>
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Enabled</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;True&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">TargetControlID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;LoginStatus1&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">BackgroundCssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;modalBackground&quot;</span>
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">PopupControlID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Panel1&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">cc1:ModalPopupExtender</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Go to the panel&rsquo;s markup (NOT UpdatePanel): set the CssClass.</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Panel</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Panel1&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">CssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;modalPopup&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Style</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;display:&nbsp;none&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">It is worth to note that if you don&rsquo;t set the display style to none, users will have an unpleasant experience: the popup dialog would&nbsp;<a class="kLink" href="http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all#" id="KonaLink4" style="color: blue !important; background-color: transparent !important; border-bottom-style: none !important; text-decoration: underline !important; cursor: pointer; font-family: verdana; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-top-style: none !important; border-right-style: none !important; border-left-style: none !important; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; border-left-color: transparent !important; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; text-transform: none !important; display: inline !important; font-variant: normal; top: 0px; right: 0px; bottom: 0px; left: 0px; position: static; background-position: initial initial !important; background-repeat: initial initial !important; " target="undefined"><font color="blue" style="color: blue !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; "><span class="kLink" style="border-top-width: 0px !important; border-top-style: none !important; border-top-color: initial !important; border-left-width: 0px !important; border-left-style: none !important; border-left-color: initial !important; border-right-width: 0px !important; border-right-style: none !important; border-right-color: initial !important; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: initial; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 1px !important; padding-left: 0px !important; color: blue !important; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; width: auto !important; float: none !important; display: inline !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; background-position: initial initial; background-repeat: initial initial; ">flash</span></font></a>&nbsp;in and out when it is loaded first time. You may also wonder why not to place this style into CssClass. Doing that will keep the popup from showing forever!</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Now we are going to work on the Login control a little bit. Here is the markup for it.</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Login</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Login1&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">DestinationPageUrl</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;~/Login.aspx&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">DisplayRememberMe</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;False&quot;</span>
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">TitleText</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">UserNameLabelText</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Employee:&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">OnAuthenticate</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Login1_Authenticate&quot;</span>
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">FailureText</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Incorrect&nbsp;employee&nbsp;or password&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Width</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;100%&quot;</span>&nbsp;
<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">VisibleWhenLoggedIn</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;False&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Login</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">We have almost everything but a Cancel button. Change to design view again. Click on Login control and select Convert to Template. Drag and drop a Button next to Login button. We make it as a Cancel button. The OnClick event handler will be implemented later.</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Button</span>&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;btnCancel&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">OnClick</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;btnCancel_Click&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Text</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Cancel&quot;</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Go to source view. This time we will move around those controls in the Login template to make it pretty. Our work on MasterPage.master is done. Let&rsquo;s visit the C# code behind it.</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 4 &#8211; Finished Login.aspx</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img border="0" height="238" id="Picture 1" src="http://aspalliance.com/ArticleFiles/1882/image004.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="338" /></p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">MasterPage.master.cs</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Copy and paste following codes to this file. Explanations are in comments.</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">using</span>&nbsp;System;
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">using</span>&nbsp;System.Web.UI.WebControls;
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">using</span>&nbsp;System.Web.Security;
&nbsp;
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">public</span>&nbsp;partial&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">class</span>&nbsp;MasterPage&nbsp;: System.Web.UI.MasterPage
{
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">protected</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">void</span>&nbsp;Page_Load(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">object</span>&nbsp;sender, EventArgs&nbsp;e)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;Popup&nbsp;dialog&nbsp;won&#39;t&nbsp;fire&nbsp;if&nbsp;user&nbsp;is already&nbsp;in.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(Request.IsAuthenticated)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoginStatus1_ModalPopupExtender.Enabled&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">false</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">else</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoginStatus1_ModalPopupExtender.Enabled&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">true</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;Authenticate&nbsp;user&#39;s&nbsp;crendential&nbsp;if&nbsp;Login button&nbsp;is&nbsp;clicked.</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">protected</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">void</span>&nbsp;Login1_Authenticate(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">object</span> sender,&nbsp;AuthenticateEventArgs&nbsp;e)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;You&nbsp;can&nbsp;add&nbsp;authentication&nbsp;logic here.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Authenticated&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;((Login1.UserName&nbsp;== <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;test&quot;</span>)&nbsp;&amp;&amp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Login1.Password&nbsp;== <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;test&quot;</span>));
&nbsp;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;Continue&nbsp;to&nbsp;display&nbsp;the&nbsp;popup&nbsp;dialog and&nbsp;failure&nbsp;text&nbsp;if&nbsp;login&nbsp;failed.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(!e.Authenticated)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoginStatus1_ModalPopupExtender.Show();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;Hide&nbsp;the&nbsp;popup&nbsp;dialog&nbsp;if&nbsp;Cancel&nbsp;button&nbsp;is clicked.</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">protected</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">void</span>&nbsp;btnCancel_Click(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">object</span> sender,&nbsp;EventArgs&nbsp;e)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LoginStatus1_ModalPopupExtender.Hide();
&nbsp;&nbsp;&nbsp;&nbsp;}
}</span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">At last, I add a few texts and a horizontal rule to this page. Listing 5 and 6 are the login failure page and success page. It&rsquo;s done!</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 5 &#8211; Login failure</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img border="0" height="214" src="http://aspalliance.com/ArticleFiles/1882/image005.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="269" /></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 6 &#8211; Login success</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img border="0" height="214" id="Picture 13" src="http://aspalliance.com/ArticleFiles/1882/image006.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="269" /></p>
</div>
<p><span id="intellitTxt"><a class="pageTitle" id="#Page3" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Summary</a></span></p>
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="font-size: 12px; ">In this article, you learn to create a modal popup login page. AJAX makes it easy to implement. With UpdatePanel, the page won&rsquo;t post back if login failed. By adding your own authentication logic, you can expand this demo easily to real world&nbsp;<a class="kLink" href="http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all#" id="KonaLink5" style="color: blue !important; background-color: transparent !important; border-bottom-style: none !important; text-decoration: underline !important; cursor: pointer; font-family: verdana; border-top-width: 0px !important; border-right-width: 0px !important; border-bottom-width: 0px !important; border-left-width: 0px !important; border-top-style: none !important; border-right-style: none !important; border-left-style: none !important; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; border-left-color: transparent !important; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; text-transform: none !important; display: inline !important; font-variant: normal; top: 0px; right: 0px; bottom: 0px; left: 0px; position: static; background-position: initial initial !important; background-repeat: initial initial !important; " target="undefined"><font color="blue" style="color: blue !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; "><span class="kLink" style="border-top-width: 0px !important; border-top-style: none !important; border-top-color: initial !important; border-left-width: 0px !important; border-left-style: none !important; border-left-color: initial !important; border-right-width: 0px !important; border-right-style: none !important; border-right-color: initial !important; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: initial; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 1px !important; padding-left: 0px !important; color: blue !important; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; width: auto !important; float: none !important; display: inline !important; font-family: Verdana, sans-serif; font-weight: normal; font-size: 13px; position: static; background-position: initial initial; background-repeat: initial initial; ">application</span></font></a>.</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ajax/how-to-create-an-asp-net-modal-popup-login-158.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Client Centric Approach of AJAX using Toolkit</title>
		<link>http://www.allfreetech.com/ajax/client-centric-approach-of-ajax-using-toolkit-151.html</link>
		<comments>http://www.allfreetech.com/ajax/client-centric-approach-of-ajax-using-toolkit-151.html#comments</comments>
		<pubDate>Fri, 29 Jan 2010 13:58:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=151</guid>
		<description><![CDATA[In this article, the author discusses the client-centric approach for AJAX using the ASP.NET AJAX Toolkit. In general, server-centric (use of Update panel) is very popular in this field. But when it comes to performance, the client-centric approach is preferred. Sandeep also demonstrates how to call a webservice using javascript. &#160; Introduction &#160; Today everything [...]]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">In this article, the author discusses the client-centric approach for AJAX using the ASP.NET AJAX Toolkit. In general, server-centric (use of Update panel) is very popular in this field. But when it comes to performance, the client-centric approach is preferred. Sandeep also demonstrates how to call a webservice using javascript.<span id="more-151"></span></span></p>
<p>&nbsp;</p>
<table class="articleViewer" style="width: 670px; position: relative; top: -21px; ">
<tbody>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span id="intellitTxt"><a class="pageTitle" id="#Page1" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Introduction</a></span></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; ">&nbsp;</div>
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="font-size: 13px; ">Today everything is changing very rapidly and technology is of no exception. Traditional web page with boring look and feel has gone obsolete. In that rhythm requirements are also changing. Among all these changes AJAX has become very popular now a days. And why not, it is so attractive and beautiful that everybody would love to have it on their web pages. It saves time for end user, saves resources for server and after all gives a new look and new experience for web browsing.</span></div>
</td>
</tr>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span id="intellitTxt"><a class="pageTitle" id="#Page2" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">System Requirements</a></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br />
					</span></font></span></font></div>
<div class="KonaBody">
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Microsoft Windows XP Professional</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>VS 2005</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>AJAXToolkit 1.0</p>
</p></div>
</td>
</tr>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span id="intellitTxt"><a class="pageTitle" id="#Page3" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Server Centric Vs Client Centric</a></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; ">&nbsp;</div>
<p></p>
<div class="KonaBody">
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Server Centric</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; There are two ways of AJAX that can be implemented using AJAXToolkit. One is the most popular method, Server Centric (using Update panel) and another one is Client Centric. There are several reasons (given below) why the server centric became so much popular.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Server centric takes very less time to implement.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>From a developer point of view, it is very easy to implement. Just put your controls inside an UpdatePanel and ScriptManager will do rest of the job.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>It keeps the developer free from JavaScript and developer can concentrate only on server side.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Requires less effort.</p>
<p class="MsoBodyTextIndent">But everything in this world comes with a cost. There are also several drawbacks that come along with this approach.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Though it does not show but internally it completes the whole page life cycle once again, which actually violates the basics of AJAX. But for an end user it never matters.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>As it completes the total page life cycle again and hence for better performance client centric is having an edge.</p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Client Centric</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>This is the most preferred approach for better performance.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>It is completely in adherence to the rules of AJAX.</p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Though its time taking to implement, but its worthy to spent time on it.</p>
</p></div>
</td>
</tr>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span id="intellitTxt"><a class="pageTitle" id="#Page4" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">How to accomplish Client Centric &ndash; Example</a></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; ">&nbsp;</div>
<p></p>
<div class="KonaBody">
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Lets move step by step to get a complete hold on this.</p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Create an AJAX enabled website</p>
<p class="MsoBodyText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Create an AJAX Enabled web site for this example. Ajax enabled website is same as normal .net website but having few more additional tags in web.config.</p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Add Webservice and Javascript</p>
<p class="MsoBodyText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Add a webservice (MyService.asmx) to the project. Also add a JS file (Jscript.js) to do the client side activities. Basically we are going to call the Webmethods present in the websevice through java script.</p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Add ScriptManager</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Add a ScriptManager to the MasterPage with tags as shown below.</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 1</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ScriptManager</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;ScriptManager1&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Scripts</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ScriptReference</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Path</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;JScript.js&quot;</span> <span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Scripts</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Services</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ServiceReference</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Path</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;MyService.asmx&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">InlineScript</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;true&quot;</span> <span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Services</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ScriptManager</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></pre>
</div>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Do necessary changes to the webservice</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You need to add the&nbsp;<span style="font-family: 'Microsoft Sans Serif', sans-serif; color: teal; ">ScriptService&nbsp;</span>attribute to the webservice class. Then add your own webmethod. Here we have added a GetServerTime() method.</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 2</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">[WebMethod]
public&nbsp;string&nbsp;GetServerTime()
{
&nbsp;&nbsp;&nbsp;&nbsp;return DateTime.Now.ToString();
}</span></pre>
</div>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Test the Webservice, see if it generates the client proxy</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; After this you should be able to test whether your webservice is ready to receive calls from the javascript. Basically the webservice URL followed with &ldquo;/js&rdquo; or &ldquo;/jsdebug&rdquo; will allow you to download the resulting client proxy. This is possible because of the presence of Scriptservice Attribute for Webservice class.</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If you will save and open this file, you will find that there will be necessary client proxy entry for each of the webmethods present in webservice.</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">The following prompt ensures that the webservice is correct and ready to use.</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><b><u>Figure 1</u></b></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img height="356" src="http://aspalliance.com/ArticleFiles/1909/image001.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="662" /></p>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Get the result by running the application</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; After this, create a button and run the following javascript function on the button click.</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 3</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;JScript&nbsp;File
function&nbsp;GetTime()
{
&nbsp;&nbsp;&nbsp; MyService.GetServerTime(onSuccess,onFailed);
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;
}</span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Here onSuccess and onFailed are the name of the functions (similar to delegates) that will be executed eventually at the success and failure of the AJAX Call. The definitions of them are given below.</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 4</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">function&nbsp;onSuccess(result)
{
&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Current&nbsp;time&nbsp;is:&nbsp;&quot;&nbsp;+ result);
}</span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; ">Listing 5</p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">function&nbsp;onFailed(result)
{
&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Error&nbsp;[&quot;&nbsp;+ result._statusCode&nbsp;+&nbsp;&quot;]&nbsp;:&nbsp;&quot;&nbsp;+&nbsp;result._message);
}</span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">Finally it will look like this:</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><img height="244" src="http://aspalliance.com/ArticleFiles/1909/image002.jpg" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="392" /></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;</p>
</p></div>
</td>
</tr>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span id="intellitTxt"><a class="pageTitle" id="#Page5" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Similarities with PageMethods</a></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; ">&nbsp;</div>
<p></p>
<div class="KonaBody">
<p class="MsoBodyText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This is almost similar to the PageMethods concept. In PageMethods there is no need to create a web service for AJAX functionality. Rather your javascript can directly call a method (should be marked as [WebMethod]) present on the code behind file of a .aspx page.</p>
</p></div>
</td>
</tr>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span id="intellitTxt"><a class="pageTitle" id="#Page6" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Differences with IcallbackEventHandler</a></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; ">&nbsp;</div>
<p></p>
<div class="KonaBody">
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; text-align: justify; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It can be said that Client centric approach might have evolved from the<span style="font-family: 'Courier New'; ">ICallbackEventHandler</span>, but actually it is much ahead of&nbsp;<span style="font-family: 'Courier New'; ">ICallbackEventHandler.</span>&nbsp;Few differences are given below:</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-align: justify; text-indent: -0.25in; "><b>1.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></b>In ICallbackEventHandler, only string types can be supplied to the server as argument. And only string types can be received from server. But in client centric approach&nbsp;<b>the parameter types and number of parameters are of no constraint</b>.&nbsp;<b>One can supply n number of parameters to the server and these can be of anytype.</b></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-align: justify; text-indent: -0.25in; ">2.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>ICallbackEventHandler was never Jserialisable. But through this newer approach Jserialization is possible.&nbsp;<b>As a result of which a server can return a datatable, dataset and your Javascript is now capable enough to receive them</b>. (Yes, it was never ever possible in ICallbackEventHandler).</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-align: justify; text-indent: -0.25in; ">3.<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span>One more magic, now using Jserialization of Client Centric,&nbsp;<b>you can create objects of your server side classes at client side</b>. It may not sound so interesting, but if you start thinking, it was also never possible to create an instance of a class in your javascript. But now this is also very much possible.</p>
</p></div>
</td>
</tr>
<tr>
<td class="subtitle" colspan="2" style="text-align: left; vertical-align: top; color: rgb(204, 0, 0); font-size: 11px; font-weight: bolder; "><span id="intellitTxt"><a class="pageTitle" id="#Page7" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Conclusion</a></span></td>
</tr>
<tr>
<td class="content" colspan="2" style="text-align: left; vertical-align: top; ">
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="font-size: 13px; ">By now one must have realized that why AJAX is so popular and why client centric approach is advisable. It brought a new era to the world of AJAX. AJAX programming has never been so interesting till date. I remember few years back in the age of manual AJAX, developers used to have a headache for such things, which is now very much doable in seconds using Client Centric approach of AJAX Toolkit. And think of the widely opened possibilities. Yes, we all have to agree that the new era of web development has stepped in and a long way to go.</span></div>
<div class="KonaBody">
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; ">Download</p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Link:&nbsp;<a href="http://authors.aspalliance.com/Sacharya/AJAXEnabledWebSite1.zip" style="color: rgb(144, 11, 9); background-color: transparent; ">http://authors.aspalliance.com/Sacharya/AJAXEnabledWebSite1.zip</a></p>
</p></div>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ajax/client-centric-approach-of-ajax-using-toolkit-151.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking New York Times and Twitter with Microsoft AJAX and jQuery</title>
		<link>http://www.allfreetech.com/ajax/hacking-new-york-times-and-twitter-with-microsoft-ajax-and-jquery-139.html</link>
		<comments>http://www.allfreetech.com/ajax/hacking-new-york-times-and-twitter-with-microsoft-ajax-and-jquery-139.html#comments</comments>
		<pubDate>Sun, 24 Jan 2010 08:23:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=139</guid>
		<description><![CDATA[In this article by Dr. Jayaram Krishnaswamy, we look at two APIs, the Twitter API and the New York Times API and see how we can access data on them using the JavaScript libraries available on the Microsoft Edge Content Network also know as Microsoft Content Delivery Network (CDN). While jQuery is used to access [...]]]></description>
			<content:encoded><![CDATA[<p>In this article by <b>Dr. Jayaram Krishnaswamy</b>, we look at two APIs, the Twitter API and the New York Times API and see how we can access data on them using the JavaScript libraries available on the Microsoft Edge Content Network also know as Microsoft Content Delivery Network (CDN). While jQuery is used to access API retrieved data on the intranet web server, the Microsoft AJAX client templates are used in displaying them.<span id="more-139"></span></p>
<p>APIs (Application Programming Interface) are application-to-application programming interfaces that support harvesting information on the web using the known web standards. These APIs are provided by the entities who wish to expose parts of their resources that a third party can use. The APIs run transparent to the user and exposes just what they want to expose, with some providing access to material for public consumption with others giving access to resources based on authentication. In a sense they may be called a basic form of SAAS.</p>
<p>Amazon.com, Google etc have exposed their APIs for some time. Twitter and New York Times have also exposed their API&#39;s which can be used to do some digging into the information contained in them, a kind of web mining. Many others such as Netflix have provided their own APIs described on their web sites.</p>
<h1>What is Twitter API?</h1>
<p>Twitter API is provided by the Social Networking and Micro-blogging service. Twitter API adheres to the web standards and one can talk to Twitter using HTTP. You can just about access anything on the Twitter web site. One example of creating a Microsoft SQL Server Report using Twitter API is available here &#8211; <a href="http://www.sswug.org/articles/viewarticle.aspx?id=44106" target="_blank">Tweets with Reporting Services</a>, wherein the response from the Twitter API was in XML format. JSON (JavaScript Object Notation) is another format in which data is returned when an API call is made. In this article we will be looking at API call that returns a JSON response.</p>
<p>Twitter exposes a large number methods through their API&#39;s such as API&#39;s for Search, Timeline, Status, User, Direct Message, Friendship and many more. As previously mentioned the responses will be in XML or JSON. Also while some APIs may take parameters others may not.</p>
<h1>The Twitter API used in this tutorial</h1>
<p>We will be looking at <i>trends</i> in Twitter API exposed by the url, <a href="http://search.twiiter.com/trends.format" target="_blank">http://search.twiiter.com/trends.format</a>. We will be using the GET method and we will expect a JSON response. Since the volume of traffic may overwhelm, the calls that you can make to this in an hour are limited (also known as rate limiting) but not critical for the demo in this tutorial.</p>
<p>Here is a typical call to the <i>trends</i> method on the Twitter API. Herein we will search for <i>trends</i> on the Twitter site and expect a response in JSON, if we use <i>json</i> instead of <i>Format</i> in the next URL address.</p>
<pre style="margin-left: 40px;">Instead of:

http://search.twitter.com/trends.Format

type-in, the following for URL address,

http://search.twitter.com/trends.json
</pre>
<p>When you plug the above in a web Brower you would get a response <i>trends.json</i> which you may save to your hard drive or, use it in any way you like. The next quoted text is what you get in response (note that this is what I got on Saturday 31, 2009 and what you get will be different), the content of the file <i>trends.json</i> you saved to your computer. Note that presently you get about top ten trends from <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method:-trends" target="_blank">this</a> API call.</p>
<pre style="margin-left: 40px;">{&quot;as_of&quot;:&quot;Sat, 31 Oct 2009 20:44:46 +0000&quot;,&quot;trends&quot;:[{&quot;name&quot;:&quot;Happy Halloween&quot;,
&quot;url&quot;:&quot;http://search.twitter.com/search?q=&quot;Happy+Halloween&quot;+OR+&quot;Feliz+
Halloween&quot;&quot;},{&quot;name&quot;:&quot;#nxzerosetechaves&quot;,&quot;url&quot;:&quot;http://search.twitter.com/
search?q=#nxzerosetechaves&quot;},{&quot;name&quot;:&quot;Danyl&quot;,&quot;url&quot;:&quot;http://search.twitter.com/
search?q=Danyl&quot;},{&quot;name&quot;:&quot;#HappyHalloween&quot;,&quot;url&quot;:&quot;http://search.twitter.com/
search?q=#HappyHalloween&quot;},{&quot;name&quot;:&quot;#potterday&quot;,&quot;url&quot;:&quot;http://search.twitter.com/
search?q =#potterday&quot;},{&quot;name&quot;:&quot;X Factor&quot;,&quot;url&quot;:&quot;http://search.twitter.com/
search?q=&quot;X+ Factor&quot;&quot;},{&quot;name&quot;:&quot;It&#39;s Halloween&quot;,&quot;url&quot;:&quot;http://search.twitter.
com/search?q=&quot;It &#39;s+Halloween&quot;+OR+&quot;Its+Halloween&quot;&quot;},{&quot;name&quot;:&quot;Trick&quot;,
&quot;url&quot;:&quot;http://search.twitter.com/search?q=Trick+OR+#trick&quot;},{&quot;name&quot;:&quot;Paranormal
Activity&quot;,&quot;url&quot;:&quot;http://search.twitter.com/search?q=&quot;Paranormal+Activity&quot;&quot;},
{&quot;name&quot;:&quot;This Is It&quot;,&quot;url&quot;:&quot;http://search.twitter.com/search?q=&quot;This+Is+It&quot;&quot;}]}
</pre>
<p>First of all what you see returned is a JSON object. If you are new to JSON review <a href="http://hodentek.blogspot.com/2007/07/simple-xml-file-aka-my-hello-world-for.html" target="_blank">this</a> article on my blog. The various elements that you see such as &#39;name&#39;, &#39;url&#39; etc are fields in the response that are all described in the API documentation(look for Return Values). Some of the API calls can return a ton of information and you will have to know the API method so that you can correctly parse this data. Another thing you would notice is that the JSON object you get out is a nested object with many levels. You may need a JSON Parser to get a clearer picture of this nesting and I recommend using the online parser at <a href="http://json.parser.online.fr/" target="_blank">this</a> site. Using the above site, the JSON Object would appear as shown (only a portion is shown).</p>
<p><img src="http://www.packtpub.com/files/images/msajax-article-image01.png" /></p>
<h1>New York Times API</h1>
<p>New York Times made available to the developers sometime in the middle of <a href="http://www.readwriteweb.com/archives/the_first_new_york_times_api_i.php" target="_blank">October 2008</a> APIs that can search New York Times for various kinds of information . Just like in Twitter there are a large number of APIs that you can use such as: Article Search; Best Sellers; Campaign Finance; Congress; and many others. Interested users can get on to this resource by signing up <a href="http://developer.nytimes.com/" target="_blank">here</a> requesting what APIs they would like to use. After signing up, New York Times would provide keys for the APIs that you want to access. It is important therefore, that the call should include the keys provided to you. For example, I received keys to access the following resources: Movie Reviews, Article Search, Best Sellers and Times Newswire. The key for the Movies Reviews API appears as shown here (the one shown here has been doctored and will not work).</p>
<pre style="margin-left: 40px;">Movie Reviews API
Key: b57378910b9fd80ecc73461547c93e8a:10:50673441
</pre>
<h2>Using the New York Times API</h2>
<p>It is a valuable resource since you can get for example with the Article Search API access to more than <a href="http://open.blogs.nytimes.com/2009/02/04/announcing-the-article-search-api/" target="_blank">2.8 million articles from 1981</a>. Using this is quite simple, just paste the URL shown below into the address box of your browser. Note that the key shown here is fake (but of correct format).</p>
<pre style="margin-left: 40px;">http://api.nytimes.com/svc/search/v1/article?query=India&amp;facets=
publication_year&amp;api-key=6c208890a4880093c30020be8fe17a40:0:50633441
</pre>
<p>This will display in the browser the JSON object that is returned as shown. You can use the previously mentioned site to parse it for more friendly display.</p>
<pre style="margin-left: 40px;">{&quot;facets&quot; : {&quot;publication_year&quot; : [{&quot;count&quot; : 2724 , &quot;term&quot; : &quot;2008&quot;} ,
{&quot;count&quot; : 2345 , &quot;term&quot; : &quot;2006&quot;} , {&quot;count&quot; : 2311 , &quot;term&quot; : &quot;2009&quot;} ,
{&quot;count&quot; : 2282 , &quot;term&quot; : &quot;2007&quot;} , {&quot;count&quot; : 2144 , &quot;term&quot; : &quot;2002&quot;} ,
{&quot;count&quot; : 2111 , &quot;term&quot; : &quot;2001&quot;} , {&quot;count&quot; : 1988 , &quot;term&quot; : &quot;2005&quot;} ,
{&quot;count&quot; : 1951 , &quot;term&quot; : &quot;2004&quot;} , {&quot;count&quot; : 1921 , &quot;term&quot; : &quot;1985&quot;} ,
{&quot;count&quot; : 1798 , &quot;term&quot; : &quot;2003&quot;} , {&quot;count&quot; : 1761 , &quot;term&quot; : &quot;1999&quot;} ,
{&quot;count&quot; : 1720 , &quot;term&quot; : &quot;2000&quot;} , {&quot;count&quot; : 1642 , &quot;term&quot; : &quot;1998&quot;} ,
{&quot;count&quot; : 1442 , &quot;term&quot; : &quot;1984&quot;} , {&quot;count&quot; : 1382 , &quot;term&quot; : &quot;1986&quot;}]} ,
&quot;offset&quot; : &quot;0&quot; , &quot;results&quot; :
[{&quot;body&quot; : &quot;BARSUR, India &mdash; At the edge of the Indravati River, hundreds
of miles from the nearest international border, India effectively ends.
Indian paramilitary officers point machine guns across the water.
 The dense jungles and mountains on the other side belong to Maoist rebels
dedicated to overthrowing the government. &quot;That is their liberated&quot; ,
&quot;byline&quot; : &quot;By JIM YARDLEY&quot; , &quot;date&quot; : &quot;20091101&quot; , &quot;title&quot; :
 &quot;Maoist Rebels Widen Deadly Reach Across India&quot; , &quot;url&quot; : &quot;http://www.
nytimes.com/2009/11/01/world/asia
 /01maoist.html&quot;} ,.........(there is more of this but abbreviated here)
</pre>
<h1>Response Format</h1>
<p>As you can see the responses to the API calls return JSON objects in general of the form shown belo<!--[if gte mso 9]><xml></p>
<p><w:WordDocument></p>
<p><w:View>Normal</w:View></p>
<p><w:Zoom>0</w:Zoom></p>
<p><w:TrackMoves/></p>
<p><w:TrackFormatting/></p>
<p><w:PunctuationKerning/></p>
<p><w:ValidateAgainstSchemas/></p>
<p><w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid></p>
<p><w:IgnoreMixedContent>false</w:IgnoreMixedContent></p>
<p><w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText></p>
<p><w:DoNotPromoteQF/></p>
<p><w:LidThemeOther>EN-US</w:LidThemeOther></p>
<p><w:LidThemeAsian>X-NONE</w:LidThemeAsian></p>
<p><w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript></p>
<p><w:Compatibility></p>
<p><w:BreakWrappedTables/></p>
<p><w:SnapToGridInCell/></p>
<p><w:WrapTextWithPunct/></p>
<p><w:UseAsianBreakRules/></p>
<p><w:DontGrowAutofit/></p>
<p><w:SplitPgBreakAndParaMark/></p>
<p><w:DontVertAlignCellWithSp/></p>
<p><w:DontBreakConstrainedForcedTables/></p>
<p><w:DontVertAlignInTxbx/></p>
<p><w:Word11KerningPairs/></p>
<p><w:CachedColBalance/></p>
<p></w:Compatibility></p>
<p><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel></p>
<p><m:mathPr></p>
<p><m:mathFont m:val="Cambria Math"/></p>
<p><m:brkBin m:val="before"/></p>
<p><m:brkBinSub m:val="--"/></p>
<p><m:smallFrac m:val="off"/></p>
<p><m:dispDef/></p>
<p><m:lMargin m:val="0"/></p>
<p><m:rMargin m:val="0"/></p>
<p><m:defJc m:val="centerGroup"/></p>
<p><m:wrapIndent m:val="1440"/></p>
<p><m:intLim m:val="subSup"/></p>
<p><m:naryLim m:val="undOvr"/></p>
<p></m:mathPr></w:WordDocument></p>
<p></xml><![endif]--><!--[if gte mso 9]><xml></p>
<p><w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"</p>
<p>DefSemiHidden="true" DefQFormat="false" DefPriority="99"</p>
<p>LatentStyleCount="267"></p>
<p><w:LsdException Locked="false" Priority="0" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Normal"/></p>
<p><w:LsdException Locked="false" Priority="9" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="heading 1"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/></p>
<p><w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 1"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 2"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 3"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 4"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 5"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 6"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 7"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 8"/></p>
<p><w:LsdException Locked="false" Priority="39" Name="toc 9"/></p>
<p><w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/></p>
<p><w:LsdException Locked="false" Priority="10" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Title"/></p>
<p><w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/></p>
<p><w:LsdException Locked="false" Priority="11" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/></p>
<p><w:LsdException Locked="false" Priority="22" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Strong"/></p>
<p><w:LsdException Locked="false" Priority="20" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/></p>
<p><w:LsdException Locked="false" Priority="59" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Table Grid"/></p>
<p><w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/></p>
<p><w:LsdException Locked="false" Priority="1" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/></p>
<p><w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/></p>
<p><w:LsdException Locked="false" Priority="34" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/></p>
<p><w:LsdException Locked="false" Priority="29" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Quote"/></p>
<p><w:LsdException Locked="false" Priority="30" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/></p>
<p><w:LsdException Locked="false" Priority="60" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Shading Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="61" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light List Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="62" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Light Grid Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="63" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="64" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="65" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="66" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="67" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="68" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="69" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="70" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Dark List Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="71" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="72" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful List Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="73" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/></p>
<p><w:LsdException Locked="false" Priority="19" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/></p>
<p><w:LsdException Locked="false" Priority="21" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/></p>
<p><w:LsdException Locked="false" Priority="31" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/></p>
<p><w:LsdException Locked="false" Priority="32" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/></p>
<p><w:LsdException Locked="false" Priority="33" SemiHidden="false"</p>
<p>UnhideWhenUsed="false" QFormat="true" Name="Book Title"/></p>
<p><w:LsdException Locked="false" Priority="37" Name="Bibliography"/></p>
<p><w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/></p>
<p></w:LatentStyles></p>
<p></xml><![endif]--><br />
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:1;
mso-generic-font-family:roman;
mso-font-format:other;
mso-font-pitch:variable;
mso-font-signature:0 0 0 0 0 0;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:536871559 0 0 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman","serif";
mso-fareast-font-family:"Times New Roman";}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<p><!--[if gte mso 10]></p>
<style>
<p>/* Style Definitions */</p>
<p>table.MsoNormalTable</p>
<p>{mso-style-name:"Table Normal";</p>
<p>mso-tstyle-rowband-size:0;</p>
<p>mso-tstyle-colband-size:0;</p>
<p>mso-style-noshow:yes;</p>
<p>mso-style-priority:99;</p>
<p>mso-style-qformat:yes;</p>
<p>mso-style-parent:"";</p>
<p>mso-padding-alt:0in 5.4pt 0in 5.4pt;</p>
<p>mso-para-margin:0in;</p>
<p>mso-para-margin-bottom:.0001pt;</p>
<p>mso-pagination:widow-orphan;</p>
<p>font-size:11.0pt;</p>
<p>font-family:"Calibri","sans-serif";</p>
<p>mso-ascii-font-family:Calibri;</p>
<p>mso-ascii-theme-font:minor-latin;</p>
<p>mso-fareast-font-family:"Times New Roman";</p>
<p>mso-fareast-theme-font:minor-fareast;</p>
<p>mso-hansi-font-family:Calibri;</p>
<p>mso-hansi-theme-font:minor-latin;</p>
<p>mso-bidi-font-family:"Times New Roman";</p>
<p>mso-bidi-theme-font:minor-bidi;}</p>
</style>
<p><![endif]-->w (this one is of the form returned by the Twiiter API). What we propose to do is to use jQuery&#39;s <i>GetJSON()</i> method to get the JSON Objects and use Microsoft AJAX JavaScript files to display the data on the web page. Both jQuery javascript files and Microsoft ASP.NET AJAX files are both available on the Microsoft ECN (CDN). The <i>GetJSON()</i> method as well as the Microsoft ASP.NET AJAX templates can be easily implemented in the Visual Studio 2008 IDE. Alternatively Microsoft AJAX can also be used to retrieve data from the web sites. In this article the <i>GetJSON()</i> method will be used.</p>
<pre style="margin-left: 40px;">{&quot;x&quot;:{&quot;y&quot;:[{&quot;a1&quot;:&quot;b1&quot;, &quot;c1&quot;:&quot;d1&quot;}, {&quot;a2&quot;:&quot;b2&quot;, &quot;c2&quot;:&quot;d2&quot;}]},....
 &quot;f&quot;:&quot;g&quot;,....}
</pre>
<hr color="#ff9933" noshade="noshade" size="1" />
<p>&nbsp;</p>
<div class="header">
<h1>Accessing the APIs from the intranet</h1>
<p>When you use the APIs from your browser the APIs respond in different ways. The Twitter API will respond by allowing you to download the JSON file which you can persist to a file on your local intranet. The New York Times API on the other hand will display the JSON object directly in your browser which you can persist by saving it with the JSON extension to your local intranet server. However, these APIs cannot be directly reached by the intranet due to cross-domain browser policy (The <i>same origin</i> web security model). One may use other constructs such as plug-ins that empower the browser to overstep the same domain policy, <a href="http://www2007.org/papers/paper801.pdf" target="_blank">subspacing</a>, etc. The article does not cover these aspects. In trying out these demos the user can access these APIs via browsers and persist them to their file system.</p>
<h1>Displaying data from retrieved from the APIs</h1>
<p>As previously mentioned data will be retrieved using the API URLs which are then persisted to the intranet server. The web page created using Visual Studio is then used to display data where jQuery retrieves the persisted data from the intranet which then gets displayed by the Microsoft ASP.NET Client templates. To get an initial exposure to using these tools review <a href="http://www.eggheadcafe.com/tutorials/aspnet/0c44e024-1c33-4910-b8ca-b9d5d1348f25/aspnet-ajax-on-microsoft.aspx" target="_blank">this</a> article.</p>
<h2>Data from Twitter API</h2>
<p>The next listing created using the Visual Studio 2008 shows the how the data is retrieved and displayed. One of the main things to notice is that the parsing of the JSON object to correctly display data has to be first determined. The treeview provides a hint as to how this may be accomplished. Depending on whether it is a JSON array or a JSON object the parsing will be slightly different. Also the JSON file in the Visual Studio IDE should not have line breaks. It should be preferably in an unbroken continuous line.</p>
<h3>Listing 1: Response from Twitter API displayed using Microsoft AJAX Client library</h3>
<pre style="margin-left: 40px;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
  &lt;script src=&quot;http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js&quot;
  type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

  &lt;style type=&quot;text/css&quot;&gt; .sys-template { display:none; } &lt;/style&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjax.debug.js&quot;&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxTemplates.debug.js&quot;&gt;
&lt;/script&gt;
 &lt;script&gt;
      $(document).ready(function() {
      $(&quot;#n1&quot;).css(&quot;color&quot;, &quot;red&quot;);
      $(&quot;#n2&quot;).css(&quot;color&quot;, &quot;green&quot;); 

      });
   &lt;/script&gt;
   &lt;script type=&quot;text/javascript&quot;&gt;

     var retval;
     var url_json = &quot;http://localhost/AJAXEnabledWebSite2/TwitterType2.json&quot;;

         jQuery.getJSON(url_json, function(json) {

         retval = json;
         cdn();
     });

     function cdn() {

         $create(Sys.UI.DataView, {data: retval}, null, null, $get(&#39;SList&#39;));

     }
     &lt;/script&gt;

&lt;/head&gt;

&lt;body xmlns:dataview=&quot;javascript:Sys.UI.DataView&quot;
xmlns:sys=&quot;javascript:Sys&quot;&gt;
&lt;h1&gt;Twitter Stuff&lt;/h1&gt; 

&lt;table id=&quot;SList&quot; class=&quot;sys-template&quot;
border=&quot;1&quot; style=&quot;background-color:#B0E0E6&quot; &gt;
&lt;tr&gt;      &lt;td&gt;{{as_of}}&lt;/td&gt;
          &lt;td id=&quot;n1&quot;&gt;{{trends[0].name }}&lt;/td&gt;
          &lt;td id=&quot;n2&quot;&gt;{{trends[0].url}}&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>In the above listing, the 1st three scripts are those available on the Microsoft CDN. The fourth script does the formatting for the HTML elements via jQuery. In the fifth script, the <i>GetJSON()</i> method is called to retrieve the persisted response from the Twitter API call mentioned earlier. The persisted JSON object is in file <i>TwitterType2.json</i> (it is just a text file in VS 2008 with a json extension). The function <i>cdn()</i> creates the template for display creating a dataview using the return value from the <i>getJSON</i> call. The parsed elements from the JSON object are displayed in the table. The name space attribute in the body are important and the class attribute in the table makes the initial template hidden from the user (see the style information in the &lt;head/&gt; section. Data fields retrieved from the javascript <i>$Create()</i> are pushed to the markup blocks {{}}. Please refer to an earlier article on this site. After building the project the HTML page can be displayed using the default browser as shown. The page did not display using the Opera browser (version 9.1) but displayed as shown in Mozilla Firefox, IE 8.0, Safari, Chrome and even in my one time favorite Netscape 8.1.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/msajax-article-image02.png" /></p>
<h2>Data from New York Times</h2>
<p>The New York Times API is called as previously mentioned which gives access to India related articles as of the date the call was made. The json object returned follows the general pattern as shown here. This is just the pattern to which the data adheres. The pattern is different from the one returned from Twitter.</p>
<pre style="margin-left: 40px;">{&quot;x&quot;:{&quot;y&quot;:[&quot;a1&quot;:&quot;b1&quot;,&quot;a2&quot;,&quot;b2&quot;}]},&quot;p&quot;:&quot;q&quot;,&quot;m&quot;:[&quot;n1&quot;:&quot;valn1&quot;,&quot;n2&quot;:&quot;valn2&quot;,
&quot;n3&quot;:&quot;valn3&quot;],&quot;ts&quot;:[|&quot;v&quot;,&quot;w&quot;:&quot;z&quot;],&quot;r&quot;:&quot;s&quot;}
</pre>
<p>The next listing shown here for the sake of completeness is very similar to the one used with the Twitter API except for the json file it accesses and the display of parsed content. You are also shown how to pick the data you want to display in this listing. The <i>IndiaArticles.json</i> is the name of the json data returned from the API call persisted to the intranet. The parsing of the data is very similar to the earlier Twitter example.</p>
<h3>Listing 1: Response from New York Times API displayed using Microsoft AJAX Client library</h3>
<pre style="margin-left: 40px;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
  &lt;script src=&quot;http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js&quot;
  type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

  &lt;style type=&quot;text/css&quot;&gt; .sys-template { display:none; } &lt;/style&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjax.debug.js&quot;&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://ajax.microsoft.com/ajax/beta/0909/MicrosoftAjaxTemplates.debug.js&quot;&gt;
&lt;/script&gt;
 &lt;script&gt;
      $(document).ready(function() {
      $(&quot;#n1&quot;).css(&quot;color&quot;, &quot;red&quot;);
      $(&quot;#n2&quot;).css(&quot;color&quot;, &quot;green&quot;);
        });
   &lt;/script&gt;
   &lt;script type=&quot;text/javascript&quot;&gt;

     var retval;
     var url_json = &quot;http://localhost/AJAXEnabledWebSite2/IndiaArticles.json&quot;;

         jQuery.getJSON(url_json, function(json) {

         retval = json;
         cdn();
     });

     function cdn() {

         $create(Sys.UI.DataView, {data: retval}, null, null, $get(&#39;SList&#39;));

     }
     &lt;/script&gt;

&lt;/head&gt;

&lt;body xmlns:dataview=&quot;javascript:Sys.UI.DataView&quot;
xmlns:sys=&quot;javascript:Sys&quot;&gt;
&lt;h1&gt;New York Times Articles&lt;/h1&gt; 

&lt;table id=&quot;SList&quot; class=&quot;sys-template&quot;
border=&quot;1&quot; style=&quot;background-color:#B0E0E6&quot; &gt;
&lt;tr&gt;&lt;td&gt;{{facets}}&lt;/td&gt;
    &lt;td id=&quot;n1&quot;&gt;{{facets.publication_year[0] }}&lt;/td&gt;
    &lt;td&gt;{{facets.publication_year.count}} | {{facets.publication_year.term}}&lt;/td&gt;
    &lt;td&gt;{{offset}}&lt;/td&gt;
    &lt;td&gt;{{results[0].body}}&lt;/td&gt;
    &lt;td&gt;{{results[0].byline}}&lt;/td&gt;
    &lt;td&gt;{{results[0].date}}&lt;/td&gt;
    &lt;td&gt;{{results[0].title}}&lt;/td&gt;
    &lt;td id=&quot;l1&quot;&gt;{{results[0].url}}&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The browsed html page appears as shown in theOpera 10.0 browser.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/msajax-article-image03.png" /></p>
<h1>Summary</h1>
<p>The article described accessing data on Twitter and New York Times using jQuery and the Microsoft ASP.NET 3.5 AJAX client libraries. Both jQuery and the Microsoft AJAX are available on the Microsoft Edge Content Network.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ajax/hacking-new-york-times-and-twitter-with-microsoft-ajax-and-jquery-139.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Ajax Process Using PHP and Oracle</title>
		<link>http://www.allfreetech.com/php/creating-an-ajax-process-using-php-and-oracle-113.html</link>
		<comments>http://www.allfreetech.com/php/creating-an-ajax-process-using-php-and-oracle-113.html#comments</comments>
		<pubDate>Sat, 23 Jan 2010 07:30:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=113</guid>
		<description><![CDATA[For some time now, Ajax (Asynchronous JavaScript and XML), has been all the rage in the Web development world. Coming to the forefront with some of Google&#39;s features (Suggest, Maps, Gmail, and so on), Ajax performs server requests without the user having to submit a form or click on a link. In other words, the [...]]]></description>
			<content:encoded><![CDATA[<p>For some time now, Ajax (Asynchronous JavaScript and XML), has been all the rage in the Web development world. Coming to the forefront with some of Google&#39;s features (Suggest, Maps, Gmail, and so on), Ajax performs server requests without the user having to submit a form or click on a link. In other words, the Web browser can make the server request, and handle the response, without the user doing anything or even knowing that this is happening. The immediacy that Ajax brings is not only a great convenience, but it can also be downright cool.</p>
<p>In this recipe, I discuss all the code necessary to use Ajax to go from a simple Web page to a JavaScript function to an XMLHttpRequest to a PHP script and, finally, to an Oracle database. Along with the code, I do talk about the individual pieces with respect to the whole picture: what each chunk does and why it&#39;s important. By reading this HowTo, you will acquire not only some sample code but also, hopefully, a broader understanding of the whole Ajax concept.</p>
<p><span class="parahead1">Background</span></p>
<p>The example I&#39;ll be working with will be a registration form (or a minimal part of it, anyway). The theory is that I must confirm unique email addresses in the users table so that people cannot register multiple times using the same address. This is normally part of the validation process that comes after the user submits the form to the handling PHP script. But why should the user have to wait until then for this piece of validation? Instead, as soon as the user enters their email address and goes to the next form field, the email address will be immediately validated. But to do so, I still need to query the database, which is where Ajax comes in.</p>
<p>The simplified table structure for this example could be created with the following SQL statement (without the presence of the other tables, I&#39;ve done away with identifying keys and such).</p>
<pre>CREATE TABLE users (
	email VARCHAR2(60)
)
</pre>
<p>Obviously you could expand on this in many ways. For now, though, the important thing is that the sample code assumes you have established such a table and can connect to it from a PHP script. Some records must be in this table for the example to fully function, so you should populate it like so:</p>
<pre>INSERT INTO users (email) VALUES (&#39;this@that.com&#39;)
INSERT INTO users (email) VALUES (&#39;me@school.edu&#39;)
INSERT INTO users (email) VALUES (&#39;fake@address.net&#39;)
</pre>
<p>After you&#39;ve created and populated the table, you can begin coding. As I mentioned, there are two scripts involved. To develop and test everything, you will:</p>
<ol class="bodycopy">
<li>Create the PHP script that queries the Oracle database.</li>
<li>Manually test the PHP script to see how it works.</li>
<li>Write the JavaScript code that interacts with the PHP script.</li>
<li>Make the HTML form that ties into the JavaScript.</li>
<li>Test the entire process.</li>
</ol>
<h2>Step 1: Programming the Database Query</h2>
<p>The entire PHP script is called ajax.php. (See <a class="bodylink" href="http://www.oracle.com/technology/pub/files/ullman-ajax-samples.zip">sample code zip</a>.) The purpose of this script is to run a query in Oracle and print a message based upon the results of the query. This is all very basic Oracle, SQL, and PHP, but I&#39;ll run through it to clarify what&#39;s happening.</p>
<p>The script expects to receive an email address in the URL, which is available in the variable $_GET[&#39;email&#39;]. Then the script connects to the Oracle database. The query itself counts how many records in the users table have that email address:</p>
<pre>SELECT COUNT(*) AS NUM_ROWS FROM users WHERE email=&#39;{$_GET[&#39;email&#39;]}&#39;
</pre>
<p>This should return either 0 or 1 (or nothing at all). The query is executed in Oracle and the results are bound to the PHP $rows variable. Now $rows represents how many records in the database have that email address. With respect to Ajax, the important part of the script is shown below.</p>
<pre>if ($rows &gt; 0) {
	echo &#39;Email address has already been registered!&#39;;
} else {
	echo &#39;Email address is available!&#39;;
}
</pre>
<p>One of those two messages will be printed, based upon the value of $rows. That&#39;s all there is to this page! Absolutely no HTML is needed as this script won&#39;t be used like a standard Web page.</p>
<p>If you want to improve this script, you can confirm that the email address matches a regular expression pattern for email addresses. If so, execute the query like normal; if not, echo a statement saying that it&#39;s not a valid email address. At the very least, you&#39;d likely want to prevent SQL injection attacks. (I.e., avoid using the $_GET variable in your query without some assurances of its validity.)</p>
<p>&nbsp;</p>
<h2>Step 2: Testing the PHP Script</h2>
<p>Because this entire Ajax process involves several technologies&mdash;HTML, JavaScript, PHP, SQL, and Oracle&mdash;you&#39;ll be best off testing each piece as you go. If you don&#39;t, you can easily get lost trying to find where a problem exists. Testing this PHP script should be fairly easy:</p>
<ol class="bodycopy">
<li>Make sure you&#39;ve created the table in Oracle and populated it.</li>
<li>Edit ajax.php so that it uses valid connection parameters for your Oracle installation.</li>
<li>Save the script as ajax.php.</li>
<li>Place it in the proper directory for your Web server.</li>
<li>Go to http://yoururl/ajax.php?email=X in your Web browser.</li>
</ol>
<p>In place of X, use one of the email addresses that&#39;s already in the database (e.g., http://yoururl/ajax.php?email=this@that.com). You should see the &quot;Email address has already been registered!&quot; message. Then use an email address that has not been stored. You should see the &quot;Email address is available!&quot; text. Once you have that working, you can move on to the actual Ajax aspect of this example.</p>
<p>&nbsp;</p>
<h2>Step 3: Programming the JavaScript</h2>
<p>This section of the process is probably the most difficult unless you&#39;ve done tons of JavaScript already. In any case, the JavaScript code is the heart of the Ajax process, as it performs and handles the request from the PHP page. I&#39;ll go through this code in detail.</p>
<p>The JavaScript code will define three functions. The first creates a request object variable:</p>
<pre>function createRequestObject() {
	var ro;
	if (navigator.appName == &quot;Microsoft Internet Explorer&quot;) {
		ro = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}
</pre>
<p>You should be able to use this code for any Ajax application without modification. If the Web browser being used is Microsoft Internet Explorer, then the ro variable is initialized as an ActiveXObject of type Microsoft.XMLHTTP. For all other browsers, ro is a straightforward XMLHttpRequest type of object. That&#39;s really nothing else to it. The ro variable is now an object with all the necessary functionality to perform an asynchronous request. After creating the request object variable, this function then returns it.</p>
<p>This function is immediately called by the JavaScript code when the page is first loaded:</p>
<pre>var http = createRequestObject();
</pre>
<p>Now http represents the object and is globally available in the other functions.</p>
<p>Next up is the function that calls the PHP script:</p>
<pre>function sendRequest(email) {
	http.open(&#39;get&#39;, &#39;ajax.php?email=&#39; + encodeURIComponent(email));
	http.onreadystatechange = handleResponse;
	http.send(null);
}
</pre>
<p>This function takes one argument, which is the email address to be verified. Then it opens a connection to the PHP script. As the first argument in the open() method indicates, the request will be of type get, as opposed to post. The email address is appended to the URL, resulting in a page request like ajax.php?email=this@that.com. As you already know, this is how the PHP script is properly called. The encodeURIComponent() function just encodes the submitted value to make it URL-safe. The third line within the function tells the object what JavaScript function to call after the request has been made. The final line actually makes the request.</p>
<p>To recap, the first function, createRequestObject(), makes the object variable that&#39;s needed. The second function, sendRequest(), makes the actual request of the PHP script. Now we need a function that handles that request:</p>
<pre>function handleResponse() {
	if (http.readyState == 4) {
		document.getElementById(&#39;email_label&#39;).innerHTML = http.responseText;
	}
}
</pre>
<p>The previous function told the request object to call this function after the request has been made. This function first checks that the request was successfully made. If so, then http.readyState will be equal to 4. It could also be equal to 0 through 3 (you can search online for their actual meanings, if you care), but being equal to 4 means the request worked. The results of the request will be stored in the http.responseText attribute, the results being either of the two messages echoed by the PHP script. To be clear, if the request worked, then http.responseText will either be &quot;Email address has already been registered!&quot; or &quot;Email address is available!&quot;.</p>
<p>At this point, the JavaScript knows what the result of the PHP script was. All you need to do is get the JavaScript to notify the user of that result. An easy option would be to use an alert() box:</p>
<pre>alert(http.responseText);
</pre>
<p>If you put this within the conditional, you&#39;ll see the result when you test the whole application. (In fact, alert() is a great debugging tool to confirm what&#39;s going on in your JavaScript code.) However, I find these alerts to be annoying as an end user and would rather print the message next to the form&#39;s email input. To do so, I refer to the DOM (Document Object Model). Specifically, I assign the http.responseText to an element in my page called email_label. You&#39;ll see this in Step 4.</p>
<p>Whew! Hopefully you followed all that. To repeat, this is the most important and most complex part of this sequence. The JavaScript uses three functions to do three things: define a browser-specific request object; make a request to the PHP script; and, do something with the results of the request. If you&#39;re confused by any of this, or when it comes time to make a more complex Ajax application, you&#39;ll likely want to do a little research on JavaScript and DOM.</p>
<h2>Step 4: Making a JavaScript-functional HTML Form</h2>
<p>As I wrote previously, the premise behind this example is a registration form that takes, at the least, an email address. The minimal form would be:</p>
<pre>&lt;form action=&quot;somepage.php&quot; method=&quot;post&quot;&gt;
Email Address: &lt;input name=&quot;email&quot; type=&quot;text&quot; size=&quot;30&quot; maxlength=&quot;60&quot; /&gt;&lt;br /&gt;
First Name: &lt;input name=&quot;first_name&quot; type=&quot;text&quot; size=&quot;20&quot; maxlength=&quot;20&quot; /&gt;&lt;br /&gt;
(Rest of the form...)
&lt;/form&gt;
</pre>
<p>That&#39;s it! Well, not quite. You&#39;d want more inputs (a &quot;submit&quot; button, and so on). But for the purposes of this example, that&#39;s all you need. To avoid confusion, note that the action and method attributes here have nothing to do with the ajax.php script (which doesn&#39;t handle this form&#39;s submission).</p>
<p>Two more things are required, though. First, this form must somehow call the JavaScript code that makes the request. You could use several tricks to do that: make a clickable link, wait for the submit button to be clicked, and so on. I&#39;ve decided that once the user has entered an email address and has gone on to the next form element, the JavaScript should be called. This requires the onchange() method, which I&#39;ll add to the email input:</p>
<pre>Email Address: &lt;input name=&quot;email&quot; type=&quot;text&quot; size=&quot;30&quot; maxlength=&quot;60&quot;

onchange=&quot;sendRequest(this.form.email.value)&quot; /&gt;
</pre>
<p>As soon as the user changes the value in this input, including entering anything for the first time, and then tabs or clicks to another input, the JavaScript sendRequest() function will be called. It is fed one argument, the value of the email form input. If you look back at the JavaScript code, you can see how the value typed here gets sent to that function, which in turn is sent to the PHP script.</p>
<p>The second thing the HTML form needs is a place where JavaScript can &quot;write&quot; the received message so that it&#39;s visible to the user. As the handleResponse() function dictates, that message will be assigned to the innerHTML of an element called email_label. For this I add a span with that ID after the email address input:</p>
<pre>&lt;span id=&quot;email_label&quot;&gt;&lt;/span&gt;
</pre>
<p>That&#39;s it for tying the HTML form to the JavaScript. (See Listing 1 in the <a class="bodylink" href="http://www.oracle.com/technology/pub/files/ullman-ajax-samples.zip">sample code zip</a> for the final code.) Now it&#39;s time to see how it works!</p>
<h2>Step 5: Testing the Ajax Process</h2>
<p>Having completed the HTML and JavaScript, you should save that as ajax.html (or anything, really), then place it in the same directory as the PHP script. Load the form by running it in your Web browser, through a URL, not by opening it from the file system (i.e, go to http://yoururl/ajax.html). Type an unused email address in the proper input, then tab or click on the next input. Repeat using a stored email address.</p>
<p>The two screenshots below show the results you should see. Absolute magic!</p>
<p>&nbsp;</p>
<p><center><img alt="figure 1" src="http://www.oracle.com/technology/pub/images/ullman-ajax-f1.jpg" /></p>
<p><img alt="figure 2" src="http://www.oracle.com/technology/pub/images/ullman-ajax-f2.jpg" /></p>
<p></center></p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>In this article you&#39;ve seen how you can easily implement an Ajax process using PHP and Oracle. By doing so, server side validation is being accomplished within the client (although you should still keep server side validation as well, in case JavaScript is disabled). This particular example, in my opinion, demonstrates a nice feature for an end user, saving them from having to:</p>
<ul class="bodycopy" type="square">
<li>Submit the form</li>
<li>See that the email address has already been registered</li>
<li>Return to the form</li>
<li>Repeat</li>
</ul>
<p>Also, I think this example and the concept in general is kind of cool. And on the Web, that&#39;s not an insignificant factor.</p>
<p>Of course, there&#39;s tons more you can do with Ajax, PHP, and Oracle. The example in this article sent only one piece of data to the PHP script and retrieved just a string. You can send much more back and forth. If you have a significant amount of data to be returned to the calling page, you can have PHP return it in XML format, then use JavaScript to parse and display it. If you search online, you&#39;ll find many different examples.</p>
<p><strong><span class="boldbodycopy">Larry Ullman</span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/php/creating-an-ajax-process-using-php-and-oracle-113.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Ajax Table Editors and Viewers</title>
		<link>http://www.allfreetech.com/ajax/working-with-ajax-table-editors-and-viewers-122.html</link>
		<comments>http://www.allfreetech.com/ajax/working-with-ajax-table-editors-and-viewers-122.html#comments</comments>
		<pubDate>Sun, 17 Jan 2010 07:42:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=122</guid>
		<description><![CDATA[A typical Web application shows information that is retrieved from databases and other sources such as data feeds. In many cases, one or more Web forms let the user enter new information or modify the existing data. When the user clicks a button, the form&#39;s data is sent to the server where it is validated [...]]]></description>
			<content:encoded><![CDATA[<p>A typical Web application shows information that is retrieved from databases and other sources such as data feeds. In many cases, one or more Web forms let the user enter new information or modify the existing data. When the user clicks a button, the form&#39;s data is sent to the server where it is validated and processed. Then, the server returns the same form or another page to the user. This application model can be optimized with the help of Ajax, minimizing the network traffic and significantly improving the user&#39;s experience.<span id="more-122"></span></p>
<p>An Ajax client responds much faster to the user&#39;s actions and can provide desktop-like features, increasing user productivity. Instead of regenerating the HTML markup for every request on the server side, the user interface (UI) is loaded once in the browser and then the Ajax client retrieves only the data that it needs, updating the user interface dynamically. In addition, many data requests are sent asynchronously, meaning that they don&#39;t block the UI.</p>
<p>In this article, I&#39;ll show you how to build a Web-based table editor that allows the user to insert/delete rows and undo changes without waiting for a server response and without losing the scroll position. The table component will also act as a viewer that uses Ajax to retrieve information from a data feed. You&#39;ll learn how to use JavaScript to build a table model, create the table editor/viewer, validate data with regular expressions, access the data feed, use event handlers, and monitor the data changes in the Web browser. In addition, I&#39;ll present a very interesting technique for generating XML and HTML on the client side, using a JSP-like syntax that makes the code more readable and easier to maintain.</p>
<h2>Application Overview</h2>
<p>The sample application of this article is a portfolio editor/viewer:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f1.jpg" /></p>
<p>The user enters the stock information and is able to undo the data changes at any moment. The share prices are retrieved from a data feed so that the stock values and their gains/losses can be updated every second. When the user saves the data, the table component is switched to a read-only mode:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f2.jpg" /></p>
<p>I have already presented half of the application&#39;s code in a previous OTN article titled &quot;<a class="bodylink" href="http://www.oracle.com/technology/pub/articles/cioroianu-ajax-data.html">Enabling Data Exchange in Ajax Applications</a>,&quot; and the Ajax utility functions (contained in the ajaxUtil.js file) are reused from another OTN article of mine titled &quot;<a class="bodylink" href="http://www.oracle.com/technology/pub/articles/cioroianu_jsfajax.html">Developing Smart Web UIs with Ajax, JSF, and ADF Faces</a>.&quot; The following table specifies the article that describes each source file and the directory where you can find the file:</p>
<table align="center" border="1" cellpadding="4" cellspacing="0" class="bodycopy" width="600">
<tbody>
<tr bgcolor="#eeeeee">
<td valign="top" width="17%">
<p><strong>Article</strong></p>
</td>
<td valign="top" width="28%">
<p><strong>Directory</strong></p>
</td>
<td valign="top" width="20%">
<p><strong>File</strong></p>
</td>
<td valign="top" width="35%">
<p><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>src/ajaxapp/util</p>
</td>
<td valign="top">
<p>JSONEncoder.java</p>
</td>
<td valign="top">
<p>JSON encoding utilities</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>src/ajaxapp/util</p>
</td>
<td valign="top">
<p>XMLUtil.java</p>
</td>
<td valign="top">
<p>Schema, DOM, XPath utilities</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>src/ajaxapp/model</p>
</td>
<td valign="top">
<p>DataModel.java</p>
</td>
<td valign="top">
<p>Server-side data model</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>src/ajaxapp/model</p>
</td>
<td valign="top">
<p>StockBean.java</p>
</td>
<td valign="top">
<p>JavaBean used by the data model</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>src/ajaxapp/model</p>
</td>
<td valign="top">
<p>portfolio.xsd</p>
</td>
<td valign="top">
<p>XML Schema file for validation</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>src/ajaxapp/feed</p>
</td>
<td valign="top">
<p>DataFeed.java</p>
</td>
<td valign="top">
<p>Data feed implementation</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>src/ajaxapp/feed</p>
</td>
<td valign="top">
<p>ShareBean.java</p>
</td>
<td valign="top">
<p>JavaBean used by the data feed</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>src/ajaxapp/builder</p>
</td>
<td valign="top">
<p>JSBuilder.java</p>
</td>
<td valign="top">
<p>JavaScript code generator</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>index.jsp</p>
</td>
<td valign="top">
<p>Main page of the portfolio app</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>ajaxCtrl.jsp</p>
</td>
<td valign="top">
<p>Controller for the Ajax requests</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Smart Web UIs</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>ajaxUtil.js</p>
</td>
<td valign="top">
<p>General Ajax utilities</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Data exchange</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>ajaxLogic.js</p>
</td>
<td valign="top">
<p>App-specific Ajax utilities</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>dataModel.js</p>
</td>
<td valign="top">
<p>Client-side data model</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>dataTable.js</p>
</td>
<td valign="top">
<p>UI utilities and event handlers</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html</p>
</td>
<td valign="top">
<p>style.css</p>
</td>
<td valign="top">
<p>Cascading Style Sheet</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html/WEB-INF</p>
</td>
<td valign="top">
<p>feed.tld</p>
</td>
<td valign="top">
<p>Tag Library Descriptor</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html/WEB-INF</p>
</td>
<td valign="top">
<p>web.xml</p>
</td>
<td valign="top">
<p>Web Application Descriptor</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html/WEB-INF/tags</p>
</td>
<td valign="top">
<p>setHeader.tag</p>
</td>
<td valign="top">
<p>Tag that sets an HTTP header</p>
</td>
</tr>
<tr>
<td valign="top">
<p>This article</p>
</td>
<td valign="top">
<p>public_html/WEB-INF/tags</p>
</td>
<td valign="top">
<p>template.tag</p>
</td>
<td valign="top">
<p>Tag that invokes the JSBuilder</p>
</td>
</tr>
</tbody>
</table>
<h1>Data Models and Data Feeds</h1>
<p>Like any typical Web application, the portfolio sample has a server-side data model, which was described in <a class="bodylink" href="http://www.oracle.com/technology/pub/articles/cioroianu-ajax-data.html">&quot;Enabling Data Exchange in Ajax Applications.&quot;</a> The DataModel class can be initialized from an XML document, and its state can be encoded as a JSON string that is used to initialize the client-side data model, which is presented in this section.</p>
<h2>Building Table Models</h2>
<p>The portfolio application uses a JavaScript table model that maintains the user data and the information retrieved from the data feed with Ajax. To create the JavaScript file, open JDeveloper, select an existing project or create a new one, click <strong>File / New</strong>, expand <strong>Web Tier</strong> in the New Gallery window, select the HTML category in the left panel, select <strong>JavaScript File</strong> in the right panel and click <strong>OK</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f3.jpg" /></p>
<p>Enter the dataModel.js file name and click <strong>OK</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f4.jpg" /></p>
<p>The dataModel.js file of the sample application creates an object whose methods are similar to those defined by Swing&#39;s TableModel interface: getRowCount(), getColumnCount(), getColumnName(), getValueAt(), and setValueAt(). Here is the code that creates the data model object:</p>
<pre>var dataModel = {

    columns: [ &quot;Symbol&quot;, &quot;Shares&quot;, &quot;Paid Price&quot;,
        &quot;Last Price&quot;, &quot;Stock Value&quot;, &quot;Gain/Loss&quot; ],

    stocks: [ ],

    getRowCount: function() {
        return this.stocks.length;
    },

    getColumnCount: function() {
        return this.columns.length;
    },

    getColumnName: function(index) {
        return this.columns[index];
    },

    getValueAt: function(row, column) {
        ...
    },

    setValueAt: function(value, row, column) {
        ...
    },

    ...
}
</pre>
<p>The data model object has additional methods that return a stock&#39;s value and gain, calculate the portfolio&#39;s value and gain, get/set all stocks, insert a new stock, and delete an existing stock. You can find the code of these simple methods in the dataModel.js file.</p>
<p>The JavaScript editor of JDeveloper has many useful features such as syntax highlighting and verification, completion and parameter insight, refactoring, usage finding, brace matching, and code folding. In addition, you can use the Structure Navigator to locate declarations and functions:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f5.jpg" /></p>
<p>The JDeveloper release used here (Oracle JDeveloper 11<em>g</em> Technology Preview 2) also includes a JavaScript debugger for Firefox. To view or change the debugger settings, click <strong>Tools / Project</strong> Properties, select <strong>Run/Debug/Profile</strong> in the left panel, choose the <strong>Default</strong> profile in the right panel, and click <strong>Edit</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f6.jpg" /></p>
<p>In the Edit Run Configuration window, select <strong>Launch Settings / JavaScript</strong> in the left panel so that you can setup the debugger:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f7.jpg" /></p>
<h2>Implementing Data Feeds</h2>
<p>A data feed usually provides a Web service or an HTTP-based protocol so that it can be accessed over a network. An Ajax client, however, cannot directly connect to third-party Web services due to security restrictions imposed by the Web browser. Therefore, you need an Ajax controller running on the same server that hosts the Ajax application. This controller should connect to the third-party Web service to retrieve the data for the Ajax client. In order to keep things simple and focus on the Ajax topics, the sample application simulates the data feed, generating random share prices in the ShareBean class:</p>
<pre>package ajaxapp.feed;

public class ShareBean implements java.io.Serializable {
    private String symbol;
    private int trend;
    private double lastPrice;

    public ShareBean(String symbol) {
        this.symbol = symbol;
        trend = 1;
        lastPrice = Math.random() * 100;
    }

    public String getSymbol() {
        return symbol;
    }

    public int getTrend() {
        return trend;
    }

    public double getLastPrice() {
        lastPrice += trend * Math.random() * 0.1;
        if (Math.random() &lt; 0.2)
            trend = -trend;
        return lastPrice;
    }

}
</pre>
<p>The DataFeed class provides a getData() method that takes an array of symbols and returns the share information encoded in a JSON string:</p>
<pre>package ajaxapp.feed;

import ajaxapp.util.JSONEncoder;

import java.util.*;

public class DataFeed implements java.io.Serializable {
    private HashMap&lt;String, ShareBean&gt; shareMap;

    public DataFeed() {
        shareMap = new HashMap&lt;String, ShareBean&gt;();
    }

    public synchronized String getData(String symbols[]) {
        JSONEncoder json = new JSONEncoder();
        json.startArray();
        for (int i = 0; i &lt; symbols.length; i++) {
            String symbol = symbols[i];
            ShareBean share = shareMap.get(symbol);
            if (share == null) {
                share = new ShareBean(symbol);
                shareMap.put(symbol, share);
            }
            json.startObject();
            json.property(&quot;symbol&quot;, share.getSymbol());
            json.property(&quot;trend&quot;, share.getTrend());
            json.property(&quot;lastPrice&quot;, share.getLastPrice());
            json.endObject();
        }
        json.endArray();
        return json.toString();
    }

    public static String getData(
            DataFeed feed, String symbols[]) {
        return feed.getData(symbols);
    }

}
</pre>
<p>The static getData() method is useful for calling the instance method from a JSP page, using an expression language (EL) function that is defined in feed.tld. To create the TLD file, click <strong>File / New</strong>, select the JSP category from Web Tier in the left panel, select the JSP Tag Library item and click <strong>OK</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f8.jpg" /></p>
<p>Skip the Welcome screen of the wizard and select <strong>Project Based</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f9.jpg" /></p>
<p>Provide the feed short name, enter the /ajaxapp/feed URI and click <strong>Finish</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f10.jpg" /></p>
<p>Then, paste the &lt;function&gt; element shown below:</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;taglib ...&gt;

    &lt;tlib-version&gt;1.0&lt;/tlib-version&gt;
    &lt;short-name&gt;feed&lt;/short-name&gt;
    &lt;uri&gt;/ajaxapp/feed&lt;/uri&gt;

    &lt;function&gt;
        &lt;name&gt;getData&lt;/name&gt;
        &lt;function-class&gt;ajaxapp.feed.DataFeed&lt;/function-class&gt;
        &lt;function-signature&gt;
            java.lang.String getData(
                ajaxapp.feed.DataFeed, java.lang.String[])
        &lt;/function-signature&gt;
    &lt;/function&gt;

&lt;/taglib&gt;
</pre>
<p>The application&#39;s Ajax controller (called ajaxCtrl.jsp) uses the getData() EL function to obtain the share prices for the Ajax client. A DataFeed instance is used as an application bean in the ajaxCtrl.jsp file:</p>
<pre>&lt;%@ taglib prefix=&quot;tags&quot; tagdir=&quot;/WEB-INF/tags/&quot; %&gt;
&lt;%@ taglib prefix=&quot;feed&quot; uri=&quot;/WEB-INF/feed.tld&quot; %&gt;

&lt;tags:setHeader name=&quot;Cache-Control&quot; value=&quot;no-cache&quot;/&gt;

&lt;jsp:useBean id=&quot;dataFeed&quot; scope=&quot;application&quot;
	class=&quot;ajaxapp.feed.DataFeed&quot; /&gt;
...
${feed:getData(dataFeed, paramValues.symbol)}
</pre>
<p>It is important to set the no-cache header in order to disable the Web browser&#39;s cache. Here is the code of the setHeader.tag file:</p>
<pre>&lt;%@ attribute name=&quot;name&quot; required=&quot;true&quot; %&gt;
&lt;%@ attribute name=&quot;value&quot; required=&quot;true&quot; %&gt;

&lt;%
    String name = (String) jspContext.getAttribute(&quot;name&quot;);
    String value = (String) jspContext.getAttribute(&quot;value&quot;);
    response.setHeader(name, value);
%&gt;
</pre>
<p>Now that we have implemented a data feed on the server side, let&#39;s see how to access it from the Ajax client.</p>
<h2>Accessing Data Feeds</h2>
<p>The Ajax client sends an HTTP request to the controller, which calls the getData() method and returns the JSON string. The HTTP request must contain the parameters, which are the share symbols in the case of this example. The requestFeedInfo() function (whose code can be found in dataTable.js) gets the symbols from the data model and makes sure that each symbol is included only once, because the portfolio could contain multiple stocks with the same symbol:</p>
<pre>function requestFeedInfo() {
    var symbolSet = new Array();
    for (var i = 0; i &lt; dataModel.stocks.length; i++) {
        var symbol = dataModel.stocks[i].symbol;
        if (isValidSymbol(symbol)) {
            for (var j = 0; j &lt; symbolSet.length; j++)
                if (symbol == symbolSet[j].value)
                    symbol = null;
            if (symbol)
                symbolSet[symbolSet.length] = symbol;
        }
    }
    if (symbolSet.length &gt; 0)
        sendInfoRequest(symbolSet, feedInfoCallback);
}
</pre>
<p>The array of symbols is passed to sendInfoRequest() along with feedInfoCallback, which will be invoked when the data is received from the server. The sendInfoRequest() function aborts the previous HTTP request if it hasn&#39;t been completed, and then it builds the array of HTTP parameters that is passed to sendHttpRequest(), which builds and sends the request to the server, using the Ajax API. The sendHttpRequest() function can be found in the ajaxUtil.js file whose code was discussed in a previous OTN article entitled &quot;<a class="bodylink" href="http://www.oracle.com/technology/pub/articles/cioroianu_jsfajax.html">Developing Smart Web UIs with Ajax, JSF, and ADF Faces</a>.&quot; Here is the code of the sendInfoRequest() function from ajaxLogic.js:</p>
<pre>var ctrlURL = &quot;ajaxCtrl.jsp&quot;;
var feedRequest = null;

function sendInfoRequest(symbols, callback) {
    if (feedRequest)
        abortRequest(feedRequest);
    var params = new Array();
    for (var i = 0; i &lt; symbols.length; i++)
        params[i] = {
            name: &quot;symbol&quot;,
            value: symbols[i]
        };
    feedRequest = sendHttpRequest(
        &quot;GET&quot;, ctrlURL, params, callback);
}
</pre>
<p>The Ajax callback can be found in the dataTable.js file. The feedInfoCallback() function evaluates the JSON response with eval(request.responseText), obtaining an object tree that contains the information retrieved from the data feed. Then, it stores the latest share prices into the data model and calls updateDynamicCells() for updating the UI:</p>
<pre>function feedInfoCallback(request) {
    var feedInfo = eval(request.responseText);
    for (var i = 0; i &lt; dataModel.stocks.length; i++) {
        var symbol = dataModel.stocks[i].symbol;
        dataModel.stocks[i].lastPrice = 0;
        for (var j = 0; j &lt; feedInfo.length; j++)
            if (symbol == feedInfo[j].symbol) {
                var value = feedInfo[j].lastPrice;
                dataModel.stocks[i].lastPrice = value;
            }
    }
    updateDynamicCells();
}
</pre>
<p>Before discussing the UI code, let&#39;s see how you can use JavaScript to generate XML and HTML in the Web browser.</p>
<h1>Generating XML and HTML with JavaScript</h1>
<p>Before JSP, servlets were used to dynamically generate HTML content on the server side. It was difficult to create and maintain the servlet code, because the developer had to manually encode HTML strings within the Java code and each line of markup had to be placed in a println() statement. It was difficult to view the page structure, and it wasn&#39;t possible to use visual tools for designing the pages that were coded as servlets.</p>
<p>Today, servlets are doing very well as the foundation of the JSP technology, which provides a much better way for generating markup on the server side. On the client side, however, JavaScript has no JSP equivalent. Many developers use servlets-like coding techniques to dynamically create HTML content, or they use the DOM API. None of these solutions is easy to use when you have to generate HTML or XML with JavaScript.</p>
<h2>Using a JSP-like Syntax with JavaScript</h2>
<p>It would be much easier to use something like this</p>
<pre>&lt;tag attr=&quot;[%= value %]&quot;&gt; [%= data %] &lt;/tag&gt;</pre>
<p>instead of</p>
<pre>&quot;&lt;tag attr=\&quot;&quot; + escapeXML(value) + &quot;\&quot;&gt;&quot; + escapeXML(data) + &quot;&lt;/tag&gt;&quot;</pre>
<p>You wouldn&#39;t have to escape &quot; with \ anymore, and expressions included within the [%= %] constructs would be automatically escaped, meaning that &amp;, &lt;, &gt;, and &quot; would be replaced with &amp;amp;, &amp;lt;, &amp;gt;, and &amp;quot;, respectively. Sometimes you already have a piece of markup and you don&#39;t want to escape &amp;, &lt;, &gt;, and &quot;. In this case, you could use [%# %] instead of [%= %].</p>
<p>So you can easily view the markup&#39;s structure, the blocks of JavaScript code can be wrapped between [% and %] as in the following example:</p>
<pre>&lt;table class=&quot;tableClass&quot;&gt; [%
    for (var i = 0; i &lt; rowCount; i++) { %]
        &lt;tr class=&quot;[%= getRowClass(i) %]&quot;&gt; [%
            for (var j = 0; j &lt; columnCount; j++) { %]
                &lt;td class=&quot;[%= getCellClass(i, j) %]&quot;&gt;
                    [%# buildCell(i, j) %]
                &lt;/td&gt; [%
            } %]
        &lt;/tr&gt; [%
    } %]
&lt;/table&gt;
</pre>
<p>The above template must be translated into valid JavaScript code on the server side. Here is how this should look:</p>
<pre>var content = &quot;&quot;;
content += &quot;&lt;table class=\&quot;tableClass\&quot;&gt;&quot;;
for (var i = 0; i &lt; rowCount; i++) {
    content += &quot;&lt;tr class=\&quot;&quot;;
    content += escapeXML(getRowClass(i));
    content += &quot;\&quot;&gt;&quot;;
    for (var j = 0; j &lt; columnCount; j++) {
        content += &quot;&lt;td class=\&quot;&quot;;
        content += escapeXML(getCellClass(i, j));
        content += &quot;\&quot;&gt;&quot;;
        content += buildCell(i, j);
        content += &quot;&lt;/td&gt;&quot;;
    }
    content += &quot;&lt;/tr&gt;&quot;;
}
content += &quot;&lt;/table&gt;&quot;;
</pre>
<p>As you can see, the code is much easier to read and maintain when you use the JSP-like syntax. Let&#39;s see how to generate the JavaScript code from the template.</p>
<h2>Creating the Code Generator</h2>
<p>The JSBuilder class (of the ajaxapp.builder package) parses the template and generates the JavaScript code. In addition, the JSONEncoder class (of the ajaxapp.util package) provides the means for encoding the JavaScript strings with the character() and string() methods:</p>
<pre>package ajaxapp.util;

public class JSONEncoder {
    private StringBuilder buf;

    public JSONEncoder() {
        buf = new StringBuilder();
    }

    public void character(char ch) {
        switch (ch) {
            case &#39;\&#39;&#39;:
            case &#39;\&quot;&#39;:
            case &#39;\\&#39;:
                buf.append(&#39;\\&#39;);
                buf.append(ch);
                break;
            ...
            default:
                if (ch &gt;= 32 &amp;&amp; ch &lt; 128)
                    buf.append(ch);
                else {
                    ...
                }
        }
    }

    public void string(String str) {
        int length = str.length();
        for (int i = 0; i &lt; length; i++)
            character(str.charAt(i));
    }

    ...

    public String toString() {
        ...
        return buf.toString();
    }

    public void clear() {
        buf.setLength(0);
    }

}
</pre>
<p>The character() and string() methods of the JSONEncoder class need some modifications so they can be used by the code generator. Therefore the createEncoder() method of JSBuilder uses an inner class that overrides character() to output a JavaScript line when it meets the &#39;\n&#39; character. The string() method will output the last line, which might not end with the new line character.</p>
<pre>package ajaxapp.builder;

import ajaxapp.util.JSONEncoder;

public class JSBuilder {
    ...
    private JSONEncoder json;
    private String varName;
    private boolean isHTML;
    private PrintWriter out;

    public JSBuilder() {
        json = createEncoder();
    }

    private JSONEncoder createEncoder() {
        return new JSONEncoder() {
            private void outputLine() {
                String line = toString();
                out.println(varName + &quot; += \&quot;&quot; + line + &quot;\&quot;;&quot;);
                clear();
            }

            public void character(char ch) {
                super.character(ch);
                if (ch == &#39;\n&#39;)
                    outputLine();
            }

            public void string(String str) {
                super.string(str);
                if (toString().length() &gt; 0)
                    outputLine();
            }
        };
    }
    ...
}
</pre>
<p>The printContent() method uses the customized encoder to generate the JavaScript code that reconstructs a piece of HTML or XML content on the client side:</p>
<pre>public class JSBuilder {
    ...
    private void printContent(String content) {
        json.clear();
        json.string(content);
    }
    ...
}
</pre>
<p>The printExpr() method generates the code that escapes and appends an expression:</p>
<pre>public class JSBuilder {
    ...
    private void printExpr(String expr, boolean escapeXML) {
        if (escapeXML)
            expr = &quot;escapeXML(&quot; + expr + &quot;, &quot; + isHTML + &quot;)&quot;;
        out.println(varName + &quot; += &quot; + expr + &quot;;&quot;);
    }
    ...
}
</pre>
<p>The escapeXML() JavaScript function is included in the ajaxUtil.js file.</p>
<p>The build() method parses the template and generates the JavaScript code:</p>
<pre>public class JSBuilder {
    public static final String CODE_STARTER = &quot;[%&quot;;
    public static final String CODE_ENDER = &quot;%]&quot;;
    public static final char EXPR_STARTER = &#39;=&#39;;
    public static final char INCL_STARTER = &#39;#&#39;;
    ...
    public void build(String template, String varName,
            Writer writer, boolean isHTML) {
        this.varName = varName;
        this.isHTML = isHTML;
        out = new PrintWriter(writer, true);
        out.println(&quot;var &quot; + varName + &quot; = \&quot;\&quot;;&quot;);
        int contentStart = 0;
        int contentEnd = template.indexOf(CODE_STARTER);
        while (contentEnd != -1) {
            String content = template.substring(
                    contentStart, contentEnd);
            printContent(content);
            int codeStart = contentEnd + 2;
            int codeEnd = template.indexOf(CODE_ENDER, codeStart);
            if (codeEnd == -1) {
                codeEnd = template.length();
                template += CODE_ENDER;
            }
            char starter = template.charAt(codeStart);
            if (starter == EXPR_STARTER || starter == INCL_STARTER) {
                codeStart++;
                String expr = template.substring(codeStart, codeEnd);
                printExpr(expr, starter == EXPR_STARTER);
            } else {
                String code = template.substring(codeStart, codeEnd);
                out.println(code);
            }
            contentStart = codeEnd + 2;
            contentEnd = template.indexOf(CODE_STARTER, contentStart);
        }
        String content = template.substring(contentStart);
        printContent(content);
    }

}
</pre>
<p>With fewer than 100 lines of code, we&#39;ve built a template parser / code generator, which significantly improves the readability and maintainability of the JavaScript code that dynamically produces HTML or XML on the client-side.</p>
<h2>Using the Code Generator in JSP Pages</h2>
<p>In order to keep the JSP pages scriptless, the JSBuilder&#39;s build() method can be invoked from a custom tag file (named template.tag), which will generate a JavaScript function that returns the generated content. The function&#39;s header can be provided via an attribute, and the template can be placed between the start tag and the end tag. Here is the syntax of the custom tag:</p>
<pre>&lt;tags:template function=&quot;myTemplate(...)&quot;&gt;
     ... template ...
&lt;/tags:template&gt;
</pre>
<p>To create the tag file, click <strong>File / New</strong>, expand Web Tier in the New Gallery window, select the JSP category in the left panel, select <strong>JSP Tag File</strong> in the right panel, and click <strong>OK</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f11.jpg" /></p>
<p>Enter the template.tag file name and click <strong>OK</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f12.jpg" /></p>
<p>Then, paste the following source code. The &lt;jsp:doBody&gt; action is used in the tag file to obtain the template�s body, which is stored in a JSP variable. Then, the template is passed to the build() method, which generates the JavaScript code that will produce the content on the client side. Here is the code of the template.tag file:</p>
<pre>&lt;%@ attribute name=&quot;function&quot; required=&quot;true&quot; %&gt;
&lt;%@ attribute name=&quot;isHTML&quot; required=&quot;false&quot;
    type=&quot;java.lang.Boolean&quot; %&gt;
&lt;%@ tag import=&quot;ajaxapp.builder.JSBuilder&quot; %&gt;

&lt;script language=&quot;javascript&quot;&gt;

    function ${function} {
        &lt;jsp:doBody var=&quot;templateBody&quot;/&gt;
        &lt;%
            Boolean isHTML
                = (Boolean) jspContext.getAttribute(&quot;isHTML&quot;);
            if (isHTML == null)
                isHTML = new Boolean(false);
            String templateBody
                = (String) jspContext.getAttribute(&quot;templateBody&quot;);
            new JSBuilder().build(templateBody, &quot;content&quot;,
                jspContext.getOut(), isHTML.booleanValue());
        %&gt;
        return content;
    }

&lt;/script&gt;
</pre>
<p>The index.jsp page of the sample application uses the template tag to generate JavaScript functions that produce dynamic HTML content as well as an XML document containing the portfolio�s data. You&#39;ll see later in the article how the HTML pieces are inserted into the Web page with innerHTML. The XML document is sent to the server with XMLHttpRequest.</p>
<p>You can use Oracle JDeveloper to insert the tag into the JSP page. Select Local Tag Files: /WEB-INF/tags/ in the Component Palette. Then, drag <strong>Template</strong> from the palette and drop it on the head tag, which is shown in the Structure Navigator. JDeveloper starts a wizard that lets you enter the required function attribute in the Common Properties tab and the optional isHTML attribute in the Advanced Properties tab. Enter the buildPortfolioDoc() function header, and click <strong>Finish</strong>:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f13.jpg" /></p>
<p>JDeveloper will insert the &lt;tags:template&gt; tag within the &lt;head&gt; element of the JSP page. After that, you may enter the template�s body. Here is the code that generates JavaScript function, which returns the portfolio XML document:</p>
<pre>&lt;tags:template function=&quot;buildPortfolioDoc()&quot;&gt;
    &lt;portfolio&gt; [%
        var stocks = dataModel.stocks;
        for (var i = 0; i &lt; stocks.length; i++) {
            var stock = stocks[i]; %]
            &lt;stock symbol=&quot;[%= stock.symbol %]&quot;
                shares=&quot;[%= stock.shares %]&quot;
                paidPrice=&quot;[%= stock.paidPrice %]&quot;/&gt; [%
        } %]
    &lt;/portfolio&gt;
&lt;/tags:template&gt;
</pre>
<p>The next section shows how to use the custom tag for building the table editor/viewer.</p>
<h1>Table Editors and Viewers</h1>
<p>There are many cases when a table component must change dynamically in response to the user&#39;s actions. For example, a row could be inserted or deleted when the user clicks a button. If the table&#39;s content is recreated on the server, the user must wait while the table is reloaded and the scroll position is lost. If the user has just inserted an empty row, he/she must scroll down to find the new line where data must be entered. This is a time-consuming operation that can be avoided, using Ajax and DHTML.</p>
<h2>Initializing the User Interface</h2>
<p>The application&#39;s main page (index.jsp) declares the used tag libraries, JavaScript files, and style sheet:</p>
<pre>&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
&lt;%@ taglib prefix=&quot;tags&quot; tagdir=&quot;/WEB-INF/tags/&quot; %&gt;

&lt;html&gt;
&lt;head&gt;

&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot;&gt;

&lt;script src=&quot;ajaxUtil.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;ajaxLogic.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;dataModel.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;dataTable.js&quot;&gt;&lt;/script&gt;

...
&lt;/head&gt;
...
&lt;/html&gt;
</pre>
<p>You can use JDeveloper&#39;s editors and wizards to build JSP pages. To insert a JSP directive or a standard action, select <strong>JSP</strong> in the Component Palette, and then click or drag the desired element:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f14.jpg" /></p>
<p>Click <strong>Taglib Directive</strong> and select a JSP library that you want to use in the Web page:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f15.jpg" /></p>
<p>You can also use JDeveloper to insert HTML tags in a Web page. Select <strong>HTML</strong> in the Component Palette, select the <strong>Common</strong> category, and click <strong>Script</strong>. Then select the JavaScript file whose functions you want to call in the Web page:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f16.jpg" /></p>
<p>The body of the index.jsp page contains two elements (&lt;span&gt; and &lt;div&gt;) whose content will be set later with the help of innerHTML. The onLoad attribute indicates the function that the browser must call after loading the page:</p>
<pre>&lt;body onLoad=&quot;init()&quot;&gt;

&lt;h1 align=&quot;center&quot;&gt;&lt;span id=&quot;title&quot;&gt;&lt;/span&gt;&lt;/h1&gt;

&lt;div id=&quot;dataTable&quot;&gt;
&lt;/div&gt;

&lt;/body&gt;
</pre>
<p>The init() function tries to load the portfolio, using the sendLoadRequest() utility from the ajaxLogic.js file. If the loading succeeds, stocks are stored into the client-side data model and the editing flag is set to false. Otherwise, init() adds three empty rows and sets the editing mode. The requestFeedInfo() function is scheduled with setInterval() to be called every second:</p>
<pre>function init() {
    var stocks = sendLoadRequest();
    if (stocks &amp;&amp; stocks.length &gt; 0) {
        dataModel.setStocks(stocks);
        addDataChange();
        setEditing(false);
    } else {
        for (var i = 0; i &lt; 3; i++)
            dataModel.insertStock(i);
        addDataChange();
        setEditing(true);
    }
    setInterval(&quot;requestFeedInfo()&quot;, 1000);
}
</pre>
<h2>Using Cascading Style Sheets</h2>
<p>The sample application uses the following CSS<strong> </strong>file:</p>
<pre>BODY { background: #FFFFFF; color: #000000; }
TH { font-weight: bold;
     background-color: #EEF8FF;
     border-top: 1px solid #CCCCCC;
     border-right: 1px solid #CCCCCC;
     border-bottom: 1px solid #CCCCCC; }
TD { font-weight: normal;
     background-color: #FFFFFF;
     border-right: 1px solid #CCCCCC;
     border-bottom: 1px solid #CCCCCC; }
TH.symbol, TD.symbol { text-align: left;
     border-left: 1px solid #CCCCCC; }
TH.number, TD.number { text-align: right; }
TD.button { text-align: center; }
TD.leftButton { text-align: center;
     border-left: 1px solid #CCCCCC; }
BUTTON { background-color: #EEEEEE; }
INPUT.valid { background-color: #FFFFFF; }
INPUT.error { background-color: #FFEEEE; }
SPAN.gain { color: #008000; }
SPAN.loss { color: #FF0000; }
A:link, A:visited { color: #000000;
     text-decoration: underline; }
A:hover, A:active { color: #FF0000;
     text-decoration: underline; }
</pre>
<p>You can use Oracle JDeveloper to enter the values of the CSS properties:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f17.jpg" /></p>
<h2>Creating Tables with JavaScript</h2>
<p>The JavaScript code that builds the sample application&#39;s table is generated in the index.jsp file with the custom template tag presented in the previous section. Here is the code for building a single cell of the table:</p>
<pre>&lt;tags:template function=&quot;buildCell(row, column)&quot; isHTML=&quot;true&quot;&gt; [%
    var value = &quot;&quot;;
    if (!isDynamic(row, column))
        value = dataModel.getValueAt(row, column);
    if (isEditable(row, column)) {
        var id = getInputId(row, column); %]
        &lt;input id=&quot;[%= id %]&quot; name=&quot;[%= id %]&quot; value=&quot;[%= value %]&quot;
            type=&quot;text&quot; size=&quot;[%= column == 2 ? 6 : 4 %]&quot;
            onKeyUp=&quot;validateCellData([%= row %], [%= column %])&quot;
            onChange=&quot;dataChanged([%= row %], [%= column %])&quot;&gt; [%
    } else {
        var id = getSpanId(row, column); %]
        &lt;span id=&quot;[%= id %]&quot;&gt;[%= value %]&lt;/span&gt; [%
    } %]
&lt;/tags:template&gt;
</pre>
<p>The dataTable.js file contains the JavaScript functions that are called from the template code. The isDynamic() function returns true if the cell&#39;s value is computed using data that is retrieved from the feed:</p>
<pre>function isDynamic(row, column) {
    return column &gt;= 3;
}
</pre>
<p>The isEditable() function returns true if the user can modify the cell&#39;s value:</p>
<pre>function isEditable(row, column) {
    return isEditing() &amp;&amp; column &lt; 3;
}
</pre>
<p>The getInputId() and getSpanId()<strong> </strong>functions return the IDs of the &lt;input&gt; and &lt;span&gt; elements of the cells:</p>
<pre>function getInputId(row, column) {
    return &quot;input_&quot; + row + &quot;_&quot; + column;
}

function getSpanId(row, column) {
    return &quot;span_&quot; + row + &quot;_&quot; + column;
}
</pre>
<p>The buttons and links are generated with another template. The buildButton() function accepts three parameters: the button&#39;s label, the event handler that must be called when the button (or the link) is clicked, and an optional parameter for the handler function:</p>
<pre>&lt;tags:template function=&quot;buildButton(label, handler, param)&quot;
         isHTML=&quot;true&quot;&gt; [%
    if (!param) param = &quot;&quot;; %]
    &lt;c:if test=&quot;${initParam.useButtons}&quot;&gt;
        &lt;button onClick=&quot;[%# handler %]([%# param %])&quot; type=&quot;button&quot;&gt;
            [%= label %]
        &lt;/button&gt;
    &lt;/c:if&gt;
    &lt;c:if test=&quot;${!initParam.useButtons}&quot;&gt;
        &lt;a href=&quot;javascript:[%# handler %]([%# param %])&quot;&gt;
            [%= label %]
        &lt;/a&gt;
    &lt;/c:if&gt;
&lt;/tags:template&gt;
</pre>
<p>The useButtons parameter, which is configured in the web.xml file, determines whether buildButton() generates a button or a link:</p>
<pre>&lt;web-app ...&gt;

    &lt;context-param&gt;
        &lt;param-name&gt;useButtons&lt;/param-name&gt;
        &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;
    ...
&lt;/web-app&gt;
</pre>
<p>The table&#39;s template starts with the header that contains the column names. The buildCell() and buildButton() functions are used to generate the content of the cells. The last row contains additional buttons and the totals:</p>
<pre>&lt;tags:template function=&quot;buildTable()&quot; isHTML=&quot;true&quot;&gt;
    &lt;table border=0 cellpadding=5 cellspacing=0 align=&quot;center&quot;&gt;
        &lt;tr&gt; [%
            var columnCount = dataModel.getColumnCount();
            for (var j = 0; j &lt; columnCount; j++) { %]
                &lt;th class=&quot;[%= j == 0 ? &quot;symbol&quot; : &quot;number&quot; %]&quot;&gt;
                    [%= dataModel.getColumnName(j) %]
                &lt;/th&gt; [%
            }
            if (isEditing()) { %]
                &lt;th class=&quot;header&quot; colspan=&quot;2&quot;&gt;&nbsp;&lt;/th&gt; [%
            } %]
        &lt;/tr&gt; [%
        var rowCount = dataModel.getRowCount();
        for (var i = 0; i &lt; rowCount; i++) { %]
            &lt;tr&gt; [%
                for (var j = 0; j &lt; columnCount; j++) { %]
                    &lt;td class=&quot;[%= j == 0 ? &quot;symbol&quot; : &quot;number&quot; %]&quot;&gt;
                        [%# buildCell(i, j) %]
                    &lt;/td&gt; [%
                }
                if (isEditing()) { %]
                    &lt;td class=&quot;button&quot;&gt;
                        [%# buildButton(&quot;Insert&quot;, &quot;insertAction&quot;, i) %]
                    &lt;/td&gt;
                    &lt;td class=&quot;button&quot;&gt;
                        [%# buildButton(&quot;Delete&quot;, &quot;deleteAction&quot;, i) %]
                    &lt;/td&gt; [%
                } %]
            &lt;/tr&gt; [%
        } %]
        &lt;tr&gt;
            &lt;td class=&quot;leftButton&quot; colspan=&quot;3&quot;&gt; [%
                if (isEditing()) { %]
                    [%# buildButton(&quot;Save&quot;, &quot;saveAction&quot;) %] [%
                } else { %]
                    [%# buildButton(&quot;Edit&quot;, &quot;editAction&quot;) %] [%
                } %]
            &lt;/td&gt;
            &lt;td class=&quot;number&quot;&gt;Total:&lt;/td&gt;
            &lt;td class=&quot;number&quot;&gt;&lt;span id=&quot;totalValue&quot;&gt;&lt;/span&gt;&lt;/td&gt;
            &lt;td class=&quot;number&quot;&gt;&lt;span id=&quot;totalGain&quot;&gt;&lt;/span&gt;&lt;/td&gt; [%
            if (isEditing()) { %]
                &lt;td class=&quot;button&quot;&gt;
                    [%# buildButton(&quot;Add&quot;, &quot;insertAction&quot;, rowCount) %]
                &lt;/td&gt;
                &lt;td class=&quot;button&quot;&gt;
                    [%# buildButton(&quot;Undo&quot;, &quot;undoAction&quot;) %]
                &lt;/td&gt; [%
            } %]
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/tags:template&gt;
</pre>
<p>The generated buildTable() function is called from updateTableComponent(), whose code can be found in the dataTable.js file:</p>
<pre>function updateTableComponent() {
    getElementById(&quot;dataTable&quot;).innerHTML = buildTable();
    updateDynamicCells();
    requestFeedInfo();
    if (isEditing())
        validateTableData();
}
</pre>
<p>The getElementById() function calls the document&#39;s getElementById(), which returns the DOM object representing the HTML element that has the given ID:</p>
<pre>function getElementById(id) {
    return document.getElementById(id);
}
</pre>
<p>The isEditing() function returns the value of the editing flag, which indicates whether the table component is in editing or viewing mode:</p>
<pre>var editing = false;
...
function isEditing() {
    return editing;
}
</pre>
<p>In addition to setting the editing flag, the setEditing() function modifies the page&#39;s title and updates the table component:</p>
<pre>function setEditing(value) {
    editing = value;
    var title = &quot;AJAX-based Portfolio &quot;
        + (editing ? &quot;Editor&quot; : &quot;Viewer&quot;);
    getElementById(&quot;title&quot;).innerHTML = title;
    updateTableComponent();
}
</pre>
<h2>Validating Table Editor&#39;s Data</h2>
<p>Regular expressions provide an easy way to validate data with JavaScript. For example, a share symbol can be validated with the following function, whose code can be found in dataTable.js:</p>
<pre>function isValidSymbol(symbol) {
    return symbol &amp;&amp; (symbolRE.exec(symbol) == symbol);
}
</pre>
<p>The sample application uses three regular expressions for validating the user input:</p>
<pre>var symbolRE = /[A-Za-z][A-Za-z][A-Za-z][A-Za-z]?/;
var numberRE = /\d+/;
var priceRE = /\d+\.?\d*/;
</pre>
<p>The validateCellData() function validates the value of a single cell:</p>
<pre>function validateCellData(row, column) {
    if (!isEditable(row, column))
        return true;
    var valid = false;
    var inputElem = getElementById(getInputId(row, column));
    var value = inputElem.value;
    if (value) {
        var regexp = null;
        switch (column) {
            case 0: regexp = symbolRE; break;
            case 1: regexp = numberRE; break;
            case 2: regexp = priceRE; break;
        }
        if (regexp != null)
            valid = regexp.exec(value) == value;
    }
    inputElem.className = valid ? &quot;valid&quot; : &quot;error&quot;;
    return valid;
}
</pre>
<p>User errors are signaled with the pink color of the error style:</p>
<p><img alt="" src="http://www.oracle.com/technology/pub/images/cioroianu-ajaxtables-f18.jpg" /></p>
<p>The validateTableData() function verifies the data of the whole table:</p>
<pre>function validateTableData() {
    var allValid = true;
    for (var i = 0; i &lt; dataModel.getRowCount(); i++)
        for (var j = 0; j &lt; dataModel.getColumnCount(); j++) {
            var valid = validateCellData(i, j);
            allValid = allValid &amp;&amp; valid;
        }
    return allValid;
}
</pre>
<p>Data should be revalidated on the server for security reasons. The sample application (<a class="bodylink" href="http://www.oracle.com/technology/pub/files/cioroianu-ajaxtable-sample.zip">download</a>) uses the portfolio.xsd schema for this operation.</p>
<h2>Refreshing Table Viewer&#39;s Data</h2>
<p>In a JavaScript application, data can be formatted using custom utilities, such as the formatPrice() function, which returns a string representation of a numeric price:</p>
<pre>function formatPrice(value) {
    var n = new Number(value);
    if (isNaN(n) || n == 0)
        return &quot;&nbsp;&quot;;
    return n.toFixed(2);
}
</pre>
<p>The updateDynamicCells() function updates all dynamic cells of the table. After locating the &lt;span&gt; element of each dynamic cell, the content is changed, using the innerHTML property of the &lt;span&gt; element. If the cell represents a gain or a loss, its style can be changed too, using the className property of the same &lt;span&gt; element:</p>
<pre>function updateDynamicCells() {
    for (var i = 0; i &lt; dataModel.getRowCount(); i++) {
        for (var j = 0; j &lt; dataModel.getColumnCount(); j++) {
            if (isDynamic(i, j)) {
                var value = dataModel.getValueAt(i, j);
                var spanElem = getElementById(getSpanId(i, j));
                spanElem.innerHTML = formatPrice(value);
                if (j == 5)
                    spanElem.className = value &gt;= 0 ? &quot;gain&quot; : &quot;loss&quot;;
            }
        }
    }
    var totalValue = dataModel.getTotalValue();
    var totalValueElem = getElementById(&quot;totalValue&quot;)
    totalValueElem.innerHTML = formatPrice(totalValue);
    var totalGain = dataModel.getTotalGain();
    var totalGainElem = getElementById(&quot;totalGain&quot;)
    totalGainElem.innerHTML = formatPrice(totalGain);
    totalGainElem.className = totalGain &gt;= 0 ? &quot;gain&quot; : &quot;loss&quot;;
}
</pre>
<h2>Using Event Handlers</h2>
<p>The dataTable.js file contains the code that handles the UI events. Every time the user changes the value of a cell, the browser calls the dataChanged() function, whose call is coded in value of the onChange attribute of each &lt;input&gt; element. The dataChanged() function validates the cell&#39;s data, stores the new value in the data model, updates the dynamic cells, and requests the feed information just in case the user entered a new symbol:</p>
<pre>function dataChanged(row, column) {
    validateCellData(row, column);
    var inputElem = getElementById(getInputId(row, column));
    dataModel.setValueAt(inputElem.value, row, column);
    addDataChange();
    updateDynamicCells();
    requestFeedInfo();
}
</pre>
<p>The addDataChange() function saves the stocks into the dataChanges array:</p>
<pre>var dataChanges = new Array();
...
function addDataChange() {
    dataChanges[dataChanges.length]
        = dataModel.getStocks();
}
</pre>
<p>The undoAction() function is called each time the user clicks the Undo button. The previous stocks are retrieved from the dataChanges array. Then, the data model and the table are updated:</p>
<pre>function undoAction() {
    if (dataChanges.length &gt;= 2) {
        var stocks = dataChanges[dataChanges.length-2];
        dataChanges.length--;
        dataModel.setStocks(stocks);
        updateTableComponent();
    }
}
</pre>
<p>The insertAction() function inserts a new row:</p>
<pre>function insertAction(row) {
    dataModel.insertStock(row);
    addDataChange();
    updateTableComponent();
}
</pre>
<p>The deleteAction() function deletes a row:</p>
<pre>function deleteAction(row) {
    dataModel.deleteStock(row);
    addDataChange();
    updateTableComponent();
}
</pre>
<p>The saveAction() function sends the portfolio&#39;s data to the server, using the buildPortfolioDoc() function that is generated in index.jsp and the sendSaveRequest() function whose code can be found in ajaxLogic.js. The portfolio is saved only if the entire table&#39;s data is valid:</p>
<pre>function saveAction() {
    if (validateTableData()) {
        sendSaveRequest(buildPortfolioDoc());
        setEditing(false);
    } else {
        alert(&quot;Please provide valid values for the pink fields.&quot;);
    }
}
</pre>
<p>The editAction() function just calls setEditing(true):</p>
<pre>function editAction() {
    setEditing(true);
}
</pre>
<h1>Summary</h1>
<p>In this article, you&#39;ve learned how to build Swing-like table models and implement data feeds that are accessed with the help of Ajax. Then, you&#39;ve seen how to use a JSP-like syntax for generating HTML and XML with JavaScript. Finally, you&#39;ve found out how to build table components, validate and format their data with JavaScript, define their appearance with CSS, handle events, and undo the data changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ajax/working-with-ajax-table-editors-and-viewers-122.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Multiple Selection DropDownList with AJAX HoverMenuExtender</title>
		<link>http://www.allfreetech.com/ajax/asp-net-multiple-selection-dropdownlist-with-ajax-hovermenuextender-156.html</link>
		<comments>http://www.allfreetech.com/ajax/asp-net-multiple-selection-dropdownlist-with-ajax-hovermenuextender-156.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 14:07:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=156</guid>
		<description><![CDATA[This web user control comprises the ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet, and CheckBoxListExCtrl. The final product works with or without a MasterPage and you can drag and drop more than one instance of the control on to the page. &#160; Figure 1 Figure 2 Recently, I was looking for a multiple selection dropdownlist control for [...]]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">This web user control comprises the ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet, and CheckBoxListExCtrl. The final product works with or without a MasterPage and you can drag and drop more than one instance of the control on to the page.<span id="more-156"></span></span></p>
<p>&nbsp;</p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; display: inline !important; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Figure 1</span></p>
<div class="KonaBody">
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><img height="235" src="http://aspalliance.com/ArticleFiles/1886/image001.gif" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="333" /></span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Figure 2</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><img height="308" src="http://aspalliance.com/ArticleFiles/1886/image002.gif" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="333" /></span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Recently, I was looking for a multiple selection dropdownlist control for my new project. After spending some time researching for it, I decided to put together all my finding in one web user control. This web user control consists of an ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet and&nbsp;<a href="http://www.codeproject.com/KB/miscctrl/CheckBoxlist_Value.aspx" style="color: rgb(144, 11, 9); background-color: transparent; ">CheckBoxListExCtrl</a>. The final product will work with or without a masterpage and you can drag and drop more than one instances of the control on to the page. This is not a perfect control, feel free to modify it to tailor your requirement and share your thoughts. Below is a step by step tutorial on how I have accomplished this. Hope this tutorial will give someone an idea on how to use ASP.NET AJAX HoverMenuExtender and create multiple selection dropdownlist.</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Before we begin, this is the structure of my project.</span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Figure 3</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><img border="0" height="347" src="http://aspalliance.com/ArticleFiles/1886/image003.gif" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " width="333" /></span></p>
</div>
<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span id="intellitTxt"><a class="pageTitle" id="#Page2" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Using the Code</a></span></span></p>
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">This is a usercontrol, just drag and drop. But make sure to include the ScriptManager.</span></div>
<div class="KonaBody">
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span class="Bold" style="font-weight: bold; ">The project includes:</span></span></p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>Default.aspx &ndash; this page do not use master page and user control.</span></p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>MS_With_UserControl.aspx &ndash; this page use multiple instances of the user control and no master page.</span></p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>MS_With_UserControl_and_Masterpage.aspx &ndash; this page use multiple instances of the user control and a master page.</span></p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>CheckBoxListExCtrl &#8211; How to get the CheckBoxlist Value using Javascript?</span></p>
<p class="MsoListBullet" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0.25in; text-indent: -0.25in; font-size: 10pt; font-family: Verdana; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="font-family: Symbol; ">&middot;<span style="font: normal normal normal 7pt/normal 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>The rest of the files are fairly self explanatory.</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">The code is pretty much the same except I had made a few changes to return the text of the selected checkbox. Please see comments.</span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 1 &#8212; CheckBoxListExCtrl</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">string</span>&nbsp;clientID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;UniqueID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> <span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">this</span>.ClientIDSeparator&nbsp;
&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;repeatIndex.ToString(NumberFormatInfo.InvariantInfo); <span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//09042009&nbsp;BT&nbsp;-&nbsp;var</span>
writer.WriteBeginTag(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;input&quot;</span>);
writer.WriteAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;type&quot;</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;checkbox&quot;</span>);
writer.WriteAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;name&quot;</span>,&nbsp;UniqueID <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">this</span>.IdSeparator&nbsp;
&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;repeatIndex.ToString(NumberFormatInfo.InvariantInfo));
writer.WriteAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;id&quot;</span>,&nbsp;clientID);
writer.WriteAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;value&quot;</span>, Items[repeatIndex].Value);
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(Items[repeatIndex].Selected)
&nbsp;&nbsp;&nbsp;&nbsp;writer.WriteAttribute(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;checked&quot;</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;checked&quot;</span>);
System.Web.UI.AttributeCollection&nbsp;attrs&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;Items[repeatIndex].Attributes;
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">foreach</span>&nbsp;(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">string</span>&nbsp;key&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">in</span>&nbsp;attrs.Keys)
{
&nbsp;&nbsp;&nbsp;&nbsp;writer.WriteAttribute(key,&nbsp;attrs[key]);
}
writer.Write(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;/&gt;&quot;</span>);&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//09042009&nbsp;BT&nbsp;- close&nbsp;the&nbsp;input&nbsp;tag&nbsp;</span>
writer.Write(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&lt;label&nbsp;for=&#39;&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> clientID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;&gt;&quot;</span>);&nbsp;
<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//09042009&nbsp;BT&nbsp;-&nbsp;added&nbsp;label&nbsp;to&nbsp;hold&nbsp;the&nbsp;checkbox text</span>
writer.Write(Items[repeatIndex].Text);&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//text</span>
writer.Write(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&lt;/label&gt;&quot;</span>);&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//close label&nbsp;tag</span></span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Here is the content of the JavaScript, please read the comments.</span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 2 &#8212; MultipleSelectionDDLJS.js</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/*detect&nbsp;the&nbsp;browser&nbsp;version&nbsp;and&nbsp;name*/</span>
var&nbsp;Browser&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;{
&nbsp;&nbsp;Version:&nbsp;function()&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;version&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;999;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;we&nbsp;assume&nbsp;a&nbsp;sane browser</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(navigator.appVersion.indexOf(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MSIE&quot;</span>) !<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;-1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;bah,&nbsp;IE&nbsp;again,&nbsp;lets&nbsp;downgrade&nbsp;version number</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> parseFloat(navigator.appVersion.split(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MSIE&quot;</span>)[1]);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">return</span>&nbsp;version;
&nbsp;&nbsp;}
}
function&nbsp;showIE6Tooltip(e){
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//we&nbsp;only&nbsp;want&nbsp;this&nbsp;to&nbsp;execute&nbsp;if&nbsp;ie6</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(navigator.appName==&#39;Microsoft&nbsp;Internet Explorer&#39;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp;&nbsp;Browser.Version()&nbsp;==&nbsp;6)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>(!e){var&nbsp;e&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;window.<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">event</span>;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;obj&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;e.srcElement;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempX&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">event</span>.clientX&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> (document.documentElement.scrollLeft&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;&nbsp;&nbsp;|| document.body.scrollLeft);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tempY&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">event</span>.clientY&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> (document.documentElement.scrollTop&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;&nbsp;&nbsp;|| document.body.scrollTop);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;tooltip&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> document.getElementById(&#39;ie6SelectTooltip&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.innerHTML&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;obj.options.title; <span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//set&nbsp;the&nbsp;title&nbsp;to&nbsp;the&nbsp;div</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//display&nbsp;the&nbsp;tooltip&nbsp;based&nbsp;on&nbsp;the&nbsp;mouse location</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.style.left&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;tempX;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.style.top&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;tempY+10;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.style.width&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;100%&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.style.display&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;block&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;hideIE6Tooltip(e){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//we&nbsp;only&nbsp;want&nbsp;this&nbsp;to&nbsp;execute&nbsp;if&nbsp;ie6</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(navigator.appName==&#39;Microsoft Internet&nbsp;Explorer&#39;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp;&nbsp;Browser.Version()&nbsp;==&nbsp;6)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;tooltip&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;document.getElementById(&#39;ie6SelectTooltip&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.innerHTML&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip.style.display&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;none&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/*&nbsp;get&nbsp;and&nbsp;set&nbsp;the&nbsp;selected&nbsp;checkbox&nbsp;value&nbsp;and&nbsp;
text&nbsp;and&nbsp;selected&nbsp;index&nbsp;to&nbsp;a&nbsp;hidden&nbsp;field&nbsp;*/</span>
function&nbsp;getCheckBoxListItemsChecked(elementId) {
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//var</span>
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;elementRef&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> document.getElementById(elementId);
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;checkBoxArray&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> elementRef.getElementsByTagName(&#39;input&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;checkedValues&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;checkedText&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;checkedSelIndex&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;&#39;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;myCheckBox&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">new</span>&nbsp;Array();
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">for</span>&nbsp;(var&nbsp;i&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;checkBoxArray.length; i++)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;checkBoxRef&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;checkBoxArray[i];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(checkBoxRef.<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">checked</span>&nbsp;==&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">true</span>)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//selected&nbsp;index</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(checkedSelIndex.length&nbsp;&gt;&nbsp;0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkedSelIndex&nbsp;+=&nbsp;&#39;,&nbsp;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkedSelIndex&nbsp;+=i;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//value</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(checkedValues.length&nbsp;&gt;&nbsp;0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkedValues&nbsp;+=&nbsp;&#39;,&nbsp;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkedValues&nbsp;+=&nbsp;checkBoxRef.value;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//text</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;labelArray&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> checkBoxRef.parentNode.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getElementsByTagName(&#39;label&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(labelArray.length&nbsp;&gt;&nbsp;0)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(checkedText.length&nbsp;&gt;&nbsp;0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkedText&nbsp;+=&nbsp;&#39;,&nbsp;&#39;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkedText&nbsp;+= labelArray[0].innerHTML;
&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;myCheckBox[0]&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;checkedText;
&nbsp;&nbsp;&nbsp;&nbsp;myCheckBox[1]&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;checkedValues;
&nbsp;&nbsp;&nbsp;&nbsp;myCheckBox[2]&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;checkedSelIndex;
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">return</span>&nbsp;myCheckBox;
}
function&nbsp;readCheckBoxList(chkBox,&nbsp;ddlList, hiddenFieldText,&nbsp;hiddenFieldValue,&nbsp;
hiddenFieldSelIndex)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;checkedItems&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> getCheckBoxListItemsChecked(chkBox);
&nbsp;&nbsp;&nbsp;&nbsp;$get(ddlList).options[0].innerHTML&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> checkedItems[1];&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//set&nbsp;dropdownlist&nbsp;value</span>
&nbsp;&nbsp;&nbsp;&nbsp;$get(ddlList).title&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;checkedItems[0];&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//set the&nbsp;title&nbsp;for&nbsp;the&nbsp;dropdownlist</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//set&nbsp;hiddenfield&nbsp;value</span>
&nbsp;&nbsp;&nbsp;&nbsp;$get(hiddenFieldValue).value&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> checkedItems[1];
&nbsp;&nbsp;&nbsp;&nbsp;$get(hiddenFieldText).value&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> checkedItems[0];
&nbsp;&nbsp;&nbsp;&nbsp;$get(hiddenFieldSelIndex).value&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> checkedItems[2];
}</span></span></pre>
</div>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">MultipleSelection.ascx &ndash;</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">In this page, I have HoverMenuExtender, DropDownList, CheckBoxListExCtrl, a few hidden fields and a div to display tooltip information for IE 6.0. And I have added some dummy data to my checkboxlist so it wouldn&#39;t look empty when I drag it into the page.</span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 3 &ndash; user control page</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">div</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">cc2:HoverMenuExtender</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;HoverMenuExtender1&quot;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">TargetControlID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;MultiSelectDDL&quot;</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">PopupControlID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;PanelPopUp&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">PopupPosition</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;bottom&quot;</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">OffsetX</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;6&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">PopDelay</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;25&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">HoverCssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;popupHover&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">cc2:HoverMenuExtender</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:DropDownList</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;MultiSelectDDL&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">CssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;ddlMenu&nbsp;regularText&quot;</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ListItem</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Value</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;all&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>Select<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ListItem</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:DropDownList</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Panel</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;PanelPopUp&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">CssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;popupMenu&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">cc1:CheckBoxListExCtrl</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;CheckBoxListExCtrl1&quot;</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">CssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;regularText&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ListItem</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Value</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;d1&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>Dummy&nbsp;1<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ListItem</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ListItem</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Value</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;d2&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>Dummy&nbsp;2<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ListItem</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">cc1:CheckBoxListExCtrl</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Panel</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:HiddenField</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;hf_checkBoxValue&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:HiddenField</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;hf_checkBoxText&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:HiddenField</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;hf_checkBoxSelIndex&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">div</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>&nbsp;&nbsp;&nbsp;
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">div</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">id</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;ie6SelectTooltip&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">style</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;display:none;position:absolute;padding:1px;
border:1px&nbsp;solid&nbsp;#333333;;background-color:#fffedf;font-size:smaller;
z-index:&nbsp;99;&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">div</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span></span></span></pre>
</div>
<p class="SectionHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; color: rgb(206, 0, 0); font-weight: bold; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">MultipleSelection.ascx.cs</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Here is some of the code on Page_Load event, please read comments</span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 4 &ndash; user control code behind</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">LoadJScript();
LoadCss();
<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//add&nbsp;onclick&nbsp;attributes,&nbsp;call&nbsp;the&nbsp;readCheckBoxList function&nbsp;with&nbsp;parameters</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CheckBoxListExCtrl1.Attributes.Add(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;onclick&quot;</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;readCheckBoxList(&#39;&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckBoxListExCtrl1.ClientID <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;,&#39;&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultiSelectDDL.ClientID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;,&#39;&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hf_checkBoxText.ClientID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;,&#39;&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hf_checkBoxValue.ClientID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span> <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;,&#39;&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hf_checkBoxSelIndex.ClientID <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span>&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;);&quot;</span>);
<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//for&nbsp;IE&nbsp;6.0</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MultiSelectDDL.Attributes.Add(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;onmousemove&quot;</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;showIE6Tooltip();&quot;</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultiSelectDDL.Attributes.Add(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;onmouseout&quot;</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;hideIE6Tooltip();&quot;</span>);</span></span></pre>
</div>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">I have a method to load the Style Sheet and JavaScript separately with no duplicates, if you drag and drop multiple instances of the control onto the page, it will only register the StyleSheet and JavaScript one time only. Notice that I also included ResolveUrl method so that the usercontrol will never have problem locating the StyleSheet and JavaScript.</span></p>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 5 &ndash; load style sheet and JavaScript</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//load&nbsp;style&nbsp;css</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">internal</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">void</span>&nbsp;LoadCss()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//prevent&nbsp;loading&nbsp;multiple&nbsp;css&nbsp;style sheet</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HtmlControl&nbsp;css&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">null</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span> (Session[<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MultipleSelectionDDLCSSID&quot;</span>]&nbsp;!<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">null</span>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;css&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;Page.Header.FindControl(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Session[<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MultipleSelectionDDLCSSID&quot;</span>] <span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">as</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">string</span>)&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">as</span>&nbsp;HtmlControl;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(css&nbsp;==&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">null</span>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//load&nbsp;the&nbsp;style&nbsp;sheet</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HtmlLink&nbsp;cssLink&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">new</span>&nbsp;HtmlLink();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cssLink.ID&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MultipleSelectionDDLCSSID&quot;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cssLink.Href&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;ResolveUrl(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;~/MS_Control/MultipleSelectionDDLCSS.css&quot;</span>);&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cssLink.Attributes.Add(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;rel&quot;</span>,&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;stylesheet&quot;</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cssLink.Attributes.Add(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;type&quot;</span>,&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;text/css&quot;</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//&nbsp;Add&nbsp;the&nbsp;HtmlLink&nbsp;to&nbsp;the&nbsp;Head section&nbsp;of&nbsp;the&nbsp;page.</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Page.Header.Controls.Add(cssLink);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session[<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MultipleSelectionDDLCSSID&quot;</span>]&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;cssLink.ID;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//load&nbsp;the&nbsp;javascript</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">internal</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">void</span>&nbsp;LoadJScript()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ClientScriptManager&nbsp;script&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> Page.ClientScript;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//prevent&nbsp;duplicate&nbsp;script</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">if</span>&nbsp;(!script.IsStartupScriptRegistered(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">this</span>.GetType(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MultipleSelectionDDLJS&quot;</span>))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; script.RegisterStartupScript(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">this</span>.GetType(),&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;MultipleSelectionDDLJS&quot;</span>,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&lt;script type=&#39;text/javascript&#39;&nbsp;src=&#39;&quot;</span>+ResolveUrl(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;~/MS_Control/MultipleSelectionDDLJS.js&quot;</span>) <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;&#39;&gt;&lt;/script&gt;&quot;</span>);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span></span></pre>
</div>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 6 &#8212; MS_With_UserControl_and_Masterpage.aspx</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; "><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ScriptManager</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;ScriptManager1&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;/</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:ScriptManager</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">asp:Label</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Label1&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">CssClass</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;regularText&quot;</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">Text</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;Month:&quot;</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span>
<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&lt;</span><span style="color: maroon; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">uc1:MultipleSelection</span> <span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">ID</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;MultipleSelection1&quot;</span>&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">runat</span><span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=&quot;server&quot;</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">/&gt;</span></span></span></pre>
</div>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 7 &#8212; MS_With_UserControl_and_Masterpage.aspx.cs &#8211; How to bind the data</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">DataTable&nbsp;dt&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">new</span>&nbsp;DataTable();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataColumn&nbsp;dcValue&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">new</span> DataColumn(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;Value&quot;</span>,&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">typeof</span>(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">string</span>));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataColumn&nbsp;dcText&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">new</span> DataColumn(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;Text&quot;</span>,&nbsp;<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">typeof</span>(<span style="color: blue; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">string</span>));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(dcText);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(dcValue);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataRow&nbsp;dr;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dr&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;dt.NewRow();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dr[<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;Text&quot;</span>]&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span> <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;January&quot;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dr[<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;Value&quot;</span>]&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;m1&quot;</span>;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(dr);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&hellip;
<span style="color: green; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">//datasource,&nbsp;dataTextField,&nbsp;dataValueField</span>
&nbsp;MultipleSelection1.CreateCheckBox(dt, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;Text&quot;</span>,&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;Value&quot;</span>);</span></span></pre>
</div>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 8 &#8212; How to set selected value</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">MultipleSelection1.selectedIndex&nbsp;<span style="color: red; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">=</span>&nbsp;<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">&quot;1,5,7&quot;</span>;</span></span></pre>
</div>
<p class="CodeListingHeading" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 10pt; font-family: Verdana, sans-serif; font-weight: bold; text-decoration: underline; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Listing 9 &#8212; How to get the SelectedInde, SelectedValue, SelectedText</span></p>
<div class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; ">
<pre><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="color: black; background-color: transparent; font-family: 'Courier New'; font-size: 11px; font-weight: normal; ">MultipleSelection1.sText
MultipleSelection1.sValue
MultipleSelection1.selectedIndex</span></span></pre>
</div>
</div>
<p><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span id="intellitTxt"><a class="pageTitle" id="#Page3" style="color: rgb(204, 0, 0); font-size: medium; font-weight: bolder; ">Points of Interest</a></span></span></p>
<div class="backToTop" style="font-size: 11px; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">For some reason I didn&#39;t load the ScriptManager dynamically. So, make sure you include a ScriptManager on the page before using the usercontrol or you will come across this error message: &quot;The control with ID &#39;HoverMenuExtender1&#39; requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.&quot;</span></div>
<div class="KonaBody">
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">&quot; Invalid postback or callback argument. Event validation is enabled using&hellip;&quot;.</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Initially, I was trying to modify the value of the dropdownlist through the JavaScript and I kept getting the error whenever I hit the submit button. The easiest solution was to set the EnableEventValidation = false on the page directive, but instead, I found another work around by using hidden field.</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">The tooltip (title) were displaying correctly on IE 7.0, 8.0, FireFox and Google Chrome but not in IE6.0. In order to remedy the problem, I included a separate function to show and hide the tooltip.</span></p>
<p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 6pt; margin-left: 0in; "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 13px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">I am using a checkboxlist controls and having difficulty to get the checkboxlist value and text using JavaScript. After conducting some research, I came across a class library by Trilochan Nayak. I have modified his class so that I can retrieve the value and text of the selected checkbox through the JavaScript.</span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ajax/asp-net-multiple-selection-dropdownlist-with-ajax-hovermenuextender-156.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
