<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CUQAQ3o5eip7ImA9WhRaE0U.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967</id><updated>2012-02-16T01:09:02.422-08:00</updated><category term="C#" /><category term="Windows Installation" /><category term="JQuery" /><category term="Browsers" /><category term="Blogger Hack" /><category term="css" /><category term="SQL" /><category term="Magento" /><category term="Adsense Tips" /><category term="Databases" /><category term="iPhone Development" /><category term="Blogger" /><category term="Ajax" /><category term="Blog Promotion" /><title>Script Bank</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://scriptstreasure.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>88</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/ScriptBank" /><feedburner:info uri="scriptbank" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;D0EHSH06cSp7ImA9WhRRF04.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-1784615530910637700</id><published>2011-12-01T02:33:00.000-08:00</published><updated>2011-12-01T02:33:59.319-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-01T02:33:59.319-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>How to convert unitx timestamp to date using MYSQL</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;You can convert the timestamp to date in mysql by using DATE and &lt;span class="syntax"&gt;&lt;span class="syntax_alpha syntax_alpha_functionName"&gt;FROM_UNIXTIME function. The command given bellow,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; &lt;span style="font-weight: bold;"&gt;SELECT &lt;/span&gt;DATE( FROM_UNIXTIME( `created` ) ) AS pDate &lt;span style="font-weight: bold;"&gt;FROM &lt;/span&gt;phpkit&lt;br /&gt;
&lt;br /&gt;
OUTPUT as follows,&lt;br /&gt;
------------------------------&lt;br /&gt;
2008-07-14&lt;br /&gt;
------------------------------&lt;span class="syntax"&gt;&lt;span class="syntax_alpha syntax_alpha_functionName"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-1784615530910637700?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/JJBOm1VnsB8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/1784615530910637700/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2011/12/how-to-convert-unitx-timestamp-to-date.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/1784615530910637700?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/1784615530910637700?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/JJBOm1VnsB8/how-to-convert-unitx-timestamp-to-date.html" title="How to convert unitx timestamp to date using MYSQL" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2011/12/how-to-convert-unitx-timestamp-to-date.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUEQ38_fSp7ImA9Wx9RE0w.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-8067304836584914344</id><published>2010-12-14T00:08:00.000-08:00</published><updated>2010-12-14T00:10:02.145-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-14T00:10:02.145-08:00</app:edited><title>Inline and block elements</title><content type="html">While creating an HTML page, it is important to understand the difference between the 2 elements categories inline and block to avoid coding errors and impost the CSS for the best.&lt;br /&gt;
&lt;br /&gt;
Those 2 words, ‘block’ and ‘inline’ are explicit enough by themselves..&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;block&lt;/b&gt;: an element which forms a separate block&lt;/li&gt;
&lt;li&gt;&lt;b&gt;inline&lt;/b&gt;: an element which stays inline with the rest of the content&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Block element&lt;/h3&gt;A &lt;b&gt;block element&lt;/b&gt; has the following characteristics:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Forms a block and positions itself vertically underneath with a new empty line above and under&lt;/li&gt;
&lt;li&gt;Takes all the available width based on the measure of its parent element (container)&lt;/li&gt;
&lt;li&gt;Its height changes in rapport to its content&lt;/li&gt;
&lt;li&gt;Can contains other inline and/or block elements (es: a &amp;lt;p&amp;gt; inside a &amp;lt;div&amp;gt;)&lt;/li&gt;
&lt;li&gt;Via css, we can impost a fixed &lt;b&gt;width&lt;/b&gt; and/or &lt;b&gt;height&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;Example of natural html block element: &amp;lt;div&amp;gt;,   &amp;lt;h1&amp;gt;…&amp;lt;h6&amp;gt;, &amp;lt;p&amp;gt;, &amp;lt;ul&amp;gt;, &amp;lt;ol&amp;gt;, &amp;lt;dl&amp;gt;,   &amp;lt;table&amp;gt;, &amp;lt;blockquote&amp;gt;, &amp;lt;form&amp;gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Inline elements&lt;/h3&gt;An &lt;b&gt;inline element&lt;/b&gt; has the following characteristics:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Positions itself horizontally inline with the rest of the content of its parent element (container)&lt;/li&gt;
&lt;li&gt;Takes the minimum width and height in rapport to its content&lt;/li&gt;
&lt;li&gt;Can contains ONLY other inline elements (es: an &amp;lt;img/&amp;gt; inside a &amp;lt;a&amp;gt;)&lt;/li&gt;
&lt;li&gt;Via css, we can NOT impost fixed measure&lt;/li&gt;
&lt;li&gt;Example of natural html inline elements: &amp;lt;span&amp;gt;, &amp;lt;a&amp;gt;,   &amp;lt;strong&amp;gt;, &amp;lt;em&amp;gt;, &amp;lt;img /&amp;gt;, &amp;lt;abbr&amp;gt;, &amp;lt;acronym&amp;gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Using the css display:block; and display:inline;, we can change the property of the element from block to inline or from inline to block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Concrete examples of block and inline elements&lt;/h3&gt;&lt;h4&gt;1. A paragraph (html block element &amp;lt;p&amp;gt;) at its natural state:&lt;/h4&gt;&lt;div style="border: 1px solid rgb(51, 51, 51);"&gt;The width equals the one of the container&lt;br /&gt;
The height equals the one of its content.&lt;/div&gt;&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;&lt;h4&gt;2. A paragraph with fixed measure:&lt;/h4&gt;&lt;div style="border: 2px solid rgb(204, 204, 204); height: 100px; width: 300px;"&gt;The width equals 300px (width:300px;), the height equals 100px (height:100px;).&lt;/div&gt;&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;&lt;h4&gt;3. A paragraph converted into an inline element using display:inline;&lt;/h4&gt;&lt;div style="border: 2px solid rgb(204, 204, 204); display: inline;"&gt;This paragraph is now an inline element. The width and height are at their minimum in rapport to its content.&lt;/div&gt;&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;&lt;h4&gt;4. A link (html inline element &amp;lt;a&amp;gt;) at its natural state&lt;/h4&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#" style="border: 2px solid rgb(204, 204, 204);" title="css css3 blog"&gt;The width and height are at their minimum in rapport to its content&lt;/a&gt;&lt;br /&gt;
&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;&lt;h4&gt;5. A link with fixed measure (to demonstrate that it does NOT work)&lt;/h4&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#" style="border: 2px solid rgb(204, 204, 204); height: 100px; width: 300px;" title="css css3 blog"&gt;We can NOT impost a fixed width and/or height to an inline element.&lt;/a&gt;&lt;br /&gt;
&lt;i&gt;NB: Internet Explorer applies the fixed measure by error of interpretation of the css specifics.  It should not be so!&lt;br /&gt;
&lt;br /&gt;
If you need, to give fixed measure to an inline element, you should add the &lt;b&gt;display:block;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;h4&gt;&amp;nbsp;&lt;/h4&gt;&lt;h4&gt;6. A link converted into a block element using display:block;&lt;/h4&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#" style="border: 2px solid rgb(204, 204, 204); display: block;" title="css css3 blog"&gt;This link is now a block element.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The width equals the one of its container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The height equals the one of its content.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-8067304836584914344?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/AFp5Gr3btXs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/8067304836584914344/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/12/inline-and-block-elements.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8067304836584914344?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8067304836584914344?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/AFp5Gr3btXs/inline-and-block-elements.html" title="Inline and block elements" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/12/inline-and-block-elements.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4GQXc7fCp7ImA9Wx9RE00.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-6491832674888965978</id><published>2010-12-13T22:42:00.000-08:00</published><updated>2010-12-13T22:42:00.904-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-13T22:42:00.904-08:00</app:edited><title>CSS Block &amp; CSS Inline Elements</title><content type="html">&lt;b&gt;The 3 ways that HTML elements can be displayed&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
All HTML elements are naturally displayed in one of the following ways:&lt;br /&gt;
&lt;div class="comment indent"&gt;&lt;br /&gt;
Block&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Takes up the full width available, with a new line before and after &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: red;"&gt;(&lt;/span&gt;&lt;span class="code" style="color: red;"&gt;display:block;&lt;/span&gt;&lt;span style="color: red;"&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Inline&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Takes up only as much width as it needs, and does not force new lines&lt;br /&gt;
&lt;span style="color: red;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (display:inline;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Not displayed&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Some tags, like &amp;lt;meta /&amp;gt; and &amp;lt;style&amp;gt; are not visible&lt;br /&gt;
&lt;span style="color: red;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (display:none;)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Block example&lt;/h3&gt;&amp;lt;p&amp;gt; tags and &amp;lt;div&amp;gt; tags are naturally displayed block-style.&lt;br /&gt;
&lt;br /&gt;
(I say “naturally” because you can override the display style by setting the CSS display property e.g. &lt;span style="color: red;"&gt;display:inline;&lt;/span&gt;.)&lt;br /&gt;
&lt;br /&gt;
A block-display element will span the full width of the space   available to it, and so will start on a new line in the flow of HTML.   The flow will continue on a new line after the block-display element.&lt;br /&gt;
&lt;br /&gt;
Here I’ve started a paragraph and now I’m going to insert a &amp;lt;div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: #ffff99; border: 1px solid rgb(153, 153, 153); margin: 0pt; padding: 1em;"&gt;new div inside my paragraph&lt;/div&gt;&lt;br /&gt;
and then continue the text here…&lt;br /&gt;
&lt;br /&gt;
See how the &amp;lt;div&amp;gt; jumped in and took over the full width of the space?&lt;br /&gt;
&lt;br /&gt;
Common HTML elements that are naturally block-display include:&lt;br /&gt;
&lt;dl&gt;&lt;dt&gt;&amp;lt;div&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Your general-purpose box&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;h1&amp;gt; … &amp;lt;h6&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; All headings&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;p&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Paragraph&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;ul&amp;gt;, &amp;lt;ol&amp;gt;, &amp;lt;dl&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Lists (unordered, ordered and definition)&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;li&amp;gt;, &amp;lt;dt&amp;gt;, &amp;lt;dd&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List items, definition list terms, and definition list definitions&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;table&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Tables&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;blockquote&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Like an indented paragraph, meant for quoting passages of text&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;pre&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Indicates a block of preformatted code&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;form&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; An input form&lt;/dt&gt;
&lt;dt&gt;&lt;br /&gt;
&lt;/dt&gt;
&lt;/dl&gt;&lt;h3&gt;Inline example&lt;/h3&gt;Inline-display elements don’t break the flow. They just fit in with the flow of the document.&lt;br /&gt;
&lt;br /&gt;
So here I’ve got a paragraph going on, and I’m going to add a &amp;lt;span&amp;gt; tag that &lt;i style="background-color: yellow;"&gt;has a yellow background and italic text&lt;/i&gt;. See how it just fits right in with the flow of the text?&lt;br /&gt;
&lt;br /&gt;
More elements are naturally inline-style, including:&lt;br /&gt;
&lt;br /&gt;
&lt;dl&gt;&lt;dt&gt;&amp;lt;span&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Your all-purpose inline element&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;a&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Anchor, used for links (and also to mark specific targets on a page for direct linking)&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;strong&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Used to make your content strong, displayed as bold in most browsers, replaces the narrower &amp;lt;b&amp;gt; (bold) tag&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;em&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Adds emphasis, but less strong than &amp;lt;strong&amp;gt;. Usually displayed as italic text, and replaces the old &amp;lt;i&amp;gt; (italic) tag&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;img /&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Image&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;br&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The line-break is an odd case, as it’s an inline element that   forces a new line. However, as the text carries on on the next line,   it’s not a block-level element.&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;input&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Form input fields like     &lt;input name="text" type="text" value="Text fields" /&gt;     and     &lt;input name="button" type="button" value=" Buttons " /&gt;   &lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;abbr&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Indicates an &lt;abbr title="Abbreviation"&gt;abbr.&lt;/abbr&gt; (hover to see how it works)&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dt&gt;&amp;lt;acronym&amp;gt;&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Working much like the abbreviation, but used for things like this &lt;acronym title="Three-Letter Acronym"&gt;TLA&lt;/acronym&gt;.&lt;/dt&gt;
&lt;dt&gt;&amp;nbsp;&lt;/dt&gt;
&lt;/dl&gt;&lt;h2&gt;You change the display property of any elements&lt;/h2&gt;&lt;br /&gt;
Although each HTML element has its natural display style, you can over-ride these in CSS.&lt;br /&gt;
&lt;br /&gt;
This can be very useful when you want your page to look a particular way while using semantically-correct HTML.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Examples&lt;/h3&gt;Say you want to provide a list of items, but you don’t want a big  bulleted list. You just want to say that you’re going to the store to  buy:&lt;br /&gt;
&lt;ul class="special-inline"&gt;&lt;li&gt;some fizzy drinks,&lt;/li&gt;
&lt;li&gt;a chainsaw,&lt;/li&gt;
&lt;li&gt;and some nylon stockings.&lt;/li&gt;
&lt;/ul&gt;Or maybe you want a nice toolbar, which is stricly a list (of links) and so should be marked up as a &lt;span class="term"&gt;&lt;ul&gt;.&lt;/ul&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;Here’s the code&lt;/h3&gt;&lt;br /&gt;
&lt;pre class="code"&gt;&amp;lt;ul&amp;gt;
&lt;div&gt;&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;About us&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;Products&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;FAQs&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;Contact us&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; &lt;/div&gt;&amp;lt;/ul&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;h3&gt;Here’s how it looks as a normal list&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;About us&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;Products&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;Contact us&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Just adding the class “toolbar”…&lt;/h3&gt;&lt;pre class="code"&gt;&lt;div&gt;&amp;lt;style type=”text/css”&amp;gt;

&lt;div&gt;.toolbar li {

&lt;div&gt;display:inline;
background-color:#eee;
border:1px solid;
border-color:#f3f3f3 #bbb #bbb #f3f3f3;
margin:0;
padding:.5em;
zoom: 1;&lt;/div&gt;} &lt;/div&gt;&amp;lt;/style&amp;gt; &lt;/div&gt;&amp;lt;ul class=”toolbar”&amp;gt;
&lt;div&gt;&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;About us&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;Products&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;FAQs&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href=”#”&amp;gt;Contact us&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/div&gt;&amp;lt;/ul&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;h3&gt;Here’s how it looks with the CSS styles applied&lt;/h3&gt;&lt;style type="text/css"&gt;
#toolbar li {
display:inline;
background-color:#eee;
border:1px solid;
border-color:#f3f3f3 #bbb #bbb #f3f3f3;
margin:0;
padding:.5em;
zoom: 1;
}
&lt;/style&gt;&lt;br /&gt;
&lt;ul id="toolbar"&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;About us&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;Products&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;FAQs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.blogger.com/post-create.g?blogID=5489823151892664967#"&gt;Contact us&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-6491832674888965978?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/yCNhdjdKezs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/6491832674888965978/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/12/css-block-css-inline-elements.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6491832674888965978?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6491832674888965978?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/yCNhdjdKezs/css-block-css-inline-elements.html" title="CSS Block &amp; CSS Inline Elements" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/12/css-block-css-inline-elements.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUCQnc-fyp7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-2543281405760456794</id><published>2010-10-06T06:54:00.001-07:00</published><updated>2010-10-06T06:54:23.957-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:54:23.957-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Browsers" /><title>Validating HTML5 in the browser</title><content type="html">I like to be alerted of any validation errors that sneak into my markup as soon as possible. That’s why I find the HTML Validator Extension for Firefox very hard to live (well, work) without.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it does not support HTML5. I’ve been looking hard for an alternative that does and has the same features as the HTML Validator Extension, i.e. runs locally in the browser without sending anything to a remote server and validates every page you load automatically.&lt;br /&gt;
&lt;br /&gt;
No luck.&lt;br /&gt;
&lt;br /&gt;
There are tools that validate markup by sending it to a remote server, either automatically or manually, but I don’t want that. I want to be able to check my work even though it’s behind a login or if I’m not connected to the Internet.&lt;br /&gt;
&lt;br /&gt;
If you happen to know of a browser extension that solves this problem, please let me know. It doesn’t have to be for Firefox – Opera, Chrome or Safari would be fine too as long as it runs on my Mac.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-2543281405760456794?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/R02hU6ztjYU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/2543281405760456794/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/validating-html5-in-browser.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/2543281405760456794?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/2543281405760456794?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/R02hU6ztjYU/validating-html5-in-browser.html" title="Validating HTML5 in the browser" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/validating-html5-in-browser.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYAR389fCp7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-824594767181349968</id><published>2010-10-06T06:52:00.000-07:00</published><updated>2010-10-06T06:52:26.164-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:52:26.164-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Browsers" /><title>Be careful with non-ascii characters in URLs</title><content type="html">&lt;p&gt;One thing that is rather common, especially on   websites whose content is not in English, is URLs that contain unencoded   characters such as space, &amp;aring;, &amp;auml;, or &amp;ouml;. While this works most of the time   it can cause problems.&lt;/p&gt;&lt;p&gt;Looking at &lt;a href="http://tools.ietf.org/html/rfc3986"&gt;RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax&lt;/a&gt;, characters that are allowed to be used unencoded in URLs are either reserved or unreserved. The unreserved characters are a-z, A-Z, 0-9, -, ., _, and ~. The reserved characters are used as delimiters and are :, /, ?, #, [, ], @, !, $, &amp;amp;, ', (, ), *, +, ,, ;, and =.&lt;/p&gt;&lt;p&gt;In essence this means that the only characters you can reliably use for the actual name parts of a URL are a-z, A-Z, 0-9, -, ., _, and ~. Any other characters need to be &lt;a href="http://en.wikipedia.org/wiki/Percent-encoding"&gt;Percent encoded&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;So what does using an unencoded character like space or &amp;aring; in a URL mean in practice?&lt;/p&gt;&lt;ul&gt;  &lt;li&gt;It doesn&amp;rsquo;t work in all user agents. Recent browsers seem to handle   it pretty well, but older browsers may not be able to follow links or   load images. It also causes problems for some other software that   expects URIs to be valid (Ruby&amp;rsquo;s &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI.html#M001444"&gt;URI.parse&lt;/a&gt; is one).&lt;/li&gt;
  &lt;li&gt;It may make URLs ugly and hard to read since browsers may percent   encode some of these characters before displaying them in the location   bar. This varies from browser to browser. A URL like http://example.com/&amp;aring; &amp;auml; &amp;ouml;/ may be displayed as http://example.com/&amp;aring; &amp;auml; &amp;ouml;/, http://example.com/&amp;aring;%20&amp;auml;%20&amp;ouml;/, http://example.com/%C3%A5%20%C3%A4%20%C3%B6/, or even http://example.com/&amp;radic;&amp;bull;%20&amp;radic;&amp;sect;%20&amp;radic;&amp;part;/.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;To keep things simple and predictable, consider sticking to the   unreserved characters in URLs unless you have a really strong   internationalisation requirement for using other characters.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-824594767181349968?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/2OSgz5q6MfI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/824594767181349968/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/be-careful-with-non-ascii-characters-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/824594767181349968?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/824594767181349968?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/2OSgz5q6MfI/be-careful-with-non-ascii-characters-in.html" title="Be careful with non-ascii characters in URLs" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/be-careful-with-non-ascii-characters-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4CRn08eSp7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-691284320275430952</id><published>2010-10-06T06:49:00.000-07:00</published><updated>2010-10-06T06:49:27.371-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:49:27.371-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Browsers" /><title>Remember non-vendor-prefixed CSS 3 properties (and put them last)</title><content type="html">Everybody wants to use CSS 3 now that even Internet Explorer will support parts of it once IE 9 is out. But since parts of CSS 3 are still subject to change, most browsers use a vendor prefix  for many CSS 3 properties to signal that their implemenation is “experimental” and may change in a later version of the browser.&lt;br /&gt;
&lt;br /&gt;
This means that for a property like border-radius to work cross-browser you need to specify it several times with different vendor prefixes, like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;.box {
  -moz-border-radius:10px;
  -webkit-border-radius:10px;
  border-radius:10px;
}
&lt;/pre&gt;&lt;br /&gt;
The -moz- prefix targets Firefox and other Gecko-based browsers, -webkit- is for older versions of Safari and other WebKit-based browsers, and the non-prefixed border-radius property is currently used by Safari 5, Chrome, Opera 10.5, and IE 9.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-691284320275430952?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/W4j8M6J022A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/691284320275430952/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/remember-non-vendor-prefixed-css-3.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/691284320275430952?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/691284320275430952?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/W4j8M6J022A/remember-non-vendor-prefixed-css-3.html" title="Remember non-vendor-prefixed CSS 3 properties (and put them last)" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/remember-non-vendor-prefixed-css-3.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEBQHc_cCp7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-3834113293874758357</id><published>2010-10-06T06:43:00.000-07:00</published><updated>2010-10-06T06:44:11.948-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:44:11.948-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Browsers" /><title>“Inspect element” is not the same as “View source”</title><content type="html">Tools like Firebug for Firefox, WebKit’s Web Inspector and Opera’s Dragonfly are indispensible tools for front-end Web developers, letting you view the DOM as the browser sees it.&lt;br /&gt;
&lt;br /&gt;
And that’s where these tools can actually cause some problems, or at least a bit of confusion. When you choose “Inspect element” or otherwise bring up one your browser’s DOM inspector, what you’re looking at is the document tree after the browser has applied its error correction and after any JavaScripts have manipulated the DOM. It is not necessarily the same as what you see when you choose “View source”.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
Take this invalid HTML snippet created by a hypothetical web developer, for example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;h1&amp;gt;The title&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;The first sentence.&amp;lt;strong&amp;gt;The second sentence.&amp;lt;/p&amp;gt;&amp;lt;/strong&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
The h1 is closed by an &amp;lt;/h2&amp;gt; tag, and the closing strong tag is on the wrong side of the closing p  tag. Two mistakes that can happen when you’re typing HTML by hand. This is what you will see when you view source in your browser. But what if you bring up a developer tool?&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Firebug/Firefox&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Firebug tells you that the DOM looks like this in Firefox:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;h1&amp;gt;The title&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;The first sentence.&amp;lt;strong&amp;gt;The second sentence.&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;strong&amp;gt;&amp;lt;/strong&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Hmm. Where did the &amp;lt;/h2&amp;gt; tag go? And how did the &amp;lt;/strong&amp;gt; tag end up in the right place? Error correction.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Web Inspector/Safari&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
What about the Web Inspector in Safari then? It shows this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;h1&amp;gt;The title
&amp;lt;p&amp;gt;The first sentence.&amp;lt;strong&amp;gt;The second sentence.&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;strong&amp;gt;&amp;lt;/strong&amp;gt;
&amp;lt;/h1&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Whoa! Everything is in the h1? Not what the source HTML says, and not the same as Firefox either. Again, error correction.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Dragonfly/Opera&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ok, let’s take a look in one more tool, Opera Dragonfly:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;h1&amp;gt;The title&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;
The first sentence.
&amp;lt;strong&amp;gt;The second sentence.&amp;lt;/strong&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Hey, that looks just like what the hypothetical developer probably intended to write. Yet another example of error correction.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Different browsers have different DOMs&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Note that the DOM is different in all three browsers.&lt;br /&gt;
&lt;br /&gt;
There are two lessons to be learned from this:&lt;br /&gt;
&lt;br /&gt;
1. DOM inspectors are not “View source”&lt;br /&gt;
2. Browsers use different error correction (at least until they all fully support HTML5), which is one of the reasons&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-3834113293874758357?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/OPAqNycxf9U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/3834113293874758357/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/inspect-element-is-not-same-as-view.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/3834113293874758357?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/3834113293874758357?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/OPAqNycxf9U/inspect-element-is-not-same-as-view.html" title="“Inspect element” is not the same as “View source”" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/inspect-element-is-not-same-as-view.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEAERH47cSp7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-3745592648791648605</id><published>2010-10-05T06:22:00.000-07:00</published><updated>2010-10-06T06:45:05.009-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:45:05.009-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="css" /><title>CSS Colors: Take Control Using PHP</title><content type="html">&lt;style type="text/css"&gt;
&lt;!--
blockquote {
margin:1em;
padding:.5em;
border:1px solid #aaa;
background:#f8f8f8;
}
.swatch {
 float:left;
 padding:10px;
 border:1px solid #666;
 text-align:center;
 font-family: "courier new", monospace;
 font-weight:bold;
}
.swatch-small {
 float:left;
 padding:4px 8px;
 border:1px solid #666;
 text-align:center;
 font-family: "courier new", monospace;
 font-weight:bold;
}
dt {
 margin-top:1em;
}
dd {
 margin-left:0;
}
--&gt;
&lt;/style&gt;&lt;br /&gt;
While many web sites use powerful programming environments to create HTML, these same tools are usually ignored when it comes to creating Cascading Style Sheets (CSS). This article describes how to take control of your colors in CSS using PHP. You will learn how to: &lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Centralize your color definitions using variables.&lt;/li&gt;
&lt;li&gt;Separate presentation and content by referring to colors using abstract names such as base and highlight.&lt;/li&gt;
&lt;li&gt;Automatically generate a color gradient from a single base color:&lt;br /&gt;
&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(20, 23, 17); color: #c9e3a6;" title="Background color: #141711"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-5&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(50, 57, 42); color: #c9e3a6;" title="Background color: #32392a"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(101, 114, 83); color: #c9e3a6;" title="Background color: #657253"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(151, 170, 125); color: #c9e3a6;" title="Background color: #97aa7d"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(171, 193, 141); color: #c9e3a6;" title="Background color: #abc18d"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(201, 227, 166); color: #c9e3a6;" title="Background color: #C9E3A6"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(209, 231, 179); color: #c9e3a6;" title="Background color: #d1e7b3"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(215, 234, 189); color: #c9e3a6;" title="Background color: #d7eabd"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(229, 242, 211); color: #c9e3a6;" title="Background color: #e5f2d3"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(241, 248, 233); color: #c9e3a6;" title="Background color: #f1f8e9"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(250, 253, 247); color: #c9e3a6;" title="Background color: #fafdf7"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+5&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;div style="clear: both; padding-bottom: 0.5em;"&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Automatically adjust the contrast of foreground colors so they can viewed on top of your background colors:&lt;br /&gt;
&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(20, 23, 17); color: #c9e3a6;" title="Background color: #141711"&gt;&lt;span title="Foreground color: #c9e3a6"&gt;-5&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(50, 57, 42); color: #e5f2d3;" title="Background color: #32392a"&gt;&lt;span title="Foreground color: #e5f2d3"&gt;-4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(101, 114, 83); color: white;" title="Background color: #657253"&gt;&lt;span title="Foreground color: #ffffff"&gt;-3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(151, 170, 125); color: black;" title="Background color: #97aa7d"&gt;&lt;span title="Foreground color: #000000"&gt;-2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(171, 193, 141); color: black;" title="Background color: #abc18d"&gt;&lt;span title="Foreground color: #000000"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(201, 227, 166); color: black;" title="Background color: #C9E3A6"&gt;&lt;span title="Foreground color: #000000"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(209, 231, 179); color: black;" title="Background color: #d1e7b3"&gt;&lt;span title="Foreground color: #000000"&gt;+1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(215, 234, 189); color: black;" title="Background color: #d7eabd"&gt;&lt;span title="Foreground color: #000000"&gt;+2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(229, 242, 211); color: #32392a;" title="Background color: #e5f2d3"&gt;&lt;span title="Foreground color: #32392a"&gt;+3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(241, 248, 233); color: #32392a;" title="Background color: #f1f8e9"&gt;&lt;span title="Foreground color: #32392a"&gt;+4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch-small" style="background: none repeat scroll 0% 0% rgb(250, 253, 247); color: #32392a;" title="Background color: #fafdf7"&gt;&lt;span title="Foreground color: #32392a"&gt;+5&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;div style="clear: both; padding-bottom: 0.5em;"&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Using PHP to Generate CSS&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To use PHP in your CSS file:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt; Rename your &lt;code&gt;style.css&lt;/code&gt;&lt;br /&gt;
file to &lt;code&gt;style.php&lt;/code&gt;, then add the following to the top of&lt;br /&gt;
the file:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;&amp;lt;?php header("Content-type: text/css"); ?&amp;gt;&lt;/pre&gt;This line tells the browser that the file is CSS instead of HTML.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; In your HTML files, change the stylesheet references from &lt;code&gt;style.css&lt;/code&gt; to &lt;code&gt;style.php&lt;/code&gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;&amp;lt;link rel="stylesheet" type="text/css"
 media="screen" href="style.php"&amp;gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Centralizing Your Color Definitions&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In a typical CSS file, color codes are scattered throughout the&lt;br /&gt;
page, and the same colors are used in multiple places. Unless you have&lt;br /&gt;
a talent for visualizing hex color codes, it can be hard to determine&lt;br /&gt;
which colors belong to which codes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our first goal is to name the color codes and define them in a&lt;br /&gt;
central location. Then if we want to change a color, we can change it&lt;br /&gt;
once and the change will be propagated throughout the stylesheet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Let's start with the following sample stylesheet:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;body {
 background:#fff;
 color:#333;
}
h1, h2, h3, h4 {
 color:#00840;
}
blockquote {
 color:#008400;
}&lt;/pre&gt;&lt;br /&gt;
And transform it into this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;&amp;lt;?php
header("Content-type: text/css");
$white = '#fff';
$dkgray = '#333';
$dkgreen = '#008400';
?&amp;gt;
body {
 background:&amp;lt;?=$white?&amp;gt;;
 color:&amp;lt;?=$dkgray?&amp;gt;;
}
h1, h2, h3, h4 {
 color:&amp;lt;?=$dkgreen?&amp;gt;;
}
blockquote {
 color:&amp;lt;?=$dkgreen?&amp;gt;;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Abstracting Your Colors&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
What if we wanted to make our headings red? If we changed the value&lt;br /&gt;
of &lt;code&gt;$dkgreen&lt;/code&gt;, then the variable name would not reflect the&lt;br /&gt;
actual color. Furthermore, if we change &lt;code&gt;$dkgreen&lt;/code&gt;, both&lt;br /&gt;
the heading elements and the blockquote element would change color.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We need to change the way we name our colors, and create variables&lt;br /&gt;
according to the &lt;i&gt;function&lt;/i&gt; of the color instead of the&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;value&lt;/i&gt; of the color:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;&amp;lt;?php
header("Content-type: text/css");
$pageBG = '#fff';
$pageFG = '#333';
$heading = '#a00000'
$quote = '#008400';
?&amp;gt;
body {
 background:&amp;lt;?=$pageBG?&amp;gt;;
 color:&amp;lt;?=$pageFG?&amp;gt;;
}
h1, h2, h3, h4 {
 color:&amp;lt;?=$heading?&amp;gt;;
}
blockquote {
 color:&amp;lt;?=$quote?&amp;gt;;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Generating Palettes With PHP&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Now let's take this a step further, and use PHP to generate new colors. We'll start with a base color and a highlight color, then generate a palette of lighter and darker shades: &lt;br /&gt;
&lt;br /&gt;
&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(20, 23, 17); color: #c9e3a6;" title="Background color: #141711"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-5&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(50, 57, 42); color: #c9e3a6;" title="Background color: #32392a"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(101, 114, 83); color: #c9e3a6;" title="Background color: #657253"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(151, 170, 125); color: #c9e3a6;" title="Background color: #97aa7d"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(171, 193, 141); color: #c9e3a6;" title="Background color: #abc18d"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(201, 227, 166); color: #c9e3a6;" title="Background color: #C9E3A6"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(209, 231, 179); color: #c9e3a6;" title="Background color: #d1e7b3"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(215, 234, 189); color: #c9e3a6;" title="Background color: #d7eabd"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(229, 242, 211); color: #c9e3a6;" title="Background color: #e5f2d3"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(241, 248, 233); color: #c9e3a6;" title="Background color: #f1f8e9"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(250, 253, 247); color: #c9e3a6;" title="Background color: #fafdf7"&gt;&lt;span title="Foreground color: #C9E3A6"&gt;+5&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(12, 11, 14); color: #746b8e;" title="Background color: #0c0b0e"&gt;&lt;span title="Foreground color: #746B8E"&gt;-5&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(29, 27, 36); color: #746b8e;" title="Background color: #1d1b24"&gt;&lt;span title="Foreground color: #746B8E"&gt;-4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(58, 54, 71); color: #746b8e;" title="Background color: #3a3647"&gt;&lt;span title="Foreground color: #746B8E"&gt;-3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(87, 80, 107); color: #746b8e;" title="Background color: #57506b"&gt;&lt;span title="Foreground color: #746B8E"&gt;-2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(99, 91, 121); color: #746b8e;" title="Background color: #635b79"&gt;&lt;span title="Foreground color: #746B8E"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(116, 107, 142); color: #746b8e;" title="Background color: #746B8E"&gt;&lt;span title="Foreground color: #746B8E"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(137, 129, 159); color: #746b8e;" title="Background color: #89819f"&gt;&lt;span title="Foreground color: #746B8E"&gt;+1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(151, 144, 171); color: #746b8e;" title="Background color: #9790ab"&gt;&lt;span title="Foreground color: #746B8E"&gt;+2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(186, 182, 199); color: #746b8e;" title="Background color: #bab6c7"&gt;&lt;span title="Foreground color: #746B8E"&gt;+3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(220, 218, 227); color: #746b8e;" title="Background color: #dcdae3"&gt;&lt;span title="Foreground color: #746B8E"&gt;+4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(242, 241, 244); color: #746b8e;" title="Background color: #f2f1f4"&gt;&lt;span title="Foreground color: #746B8E"&gt;+5&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;
Notice that the text is not readable on some of the swatches. Let's use PHP to adjust the foreground color, using color visibility guidelines recommended by the W3C:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(20, 23, 17); color: #c9e3a6;" title="Background color: #141711"&gt;&lt;span title="Foreground color: #c9e3a6"&gt;-5&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(50, 57, 42); color: #e5f2d3;" title="Background color: #32392a"&gt;&lt;span title="Foreground color: #e5f2d3"&gt;-4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(101, 114, 83); color: white;" title="Background color: #657253"&gt;&lt;span title="Foreground color: #ffffff"&gt;-3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(151, 170, 125); color: black;" title="Background color: #97aa7d"&gt;&lt;span title="Foreground color: #000000"&gt;-2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(171, 193, 141); color: black;" title="Background color: #abc18d"&gt;&lt;span title="Foreground color: #000000"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(201, 227, 166); color: black;" title="Background color: #C9E3A6"&gt;&lt;span title="Foreground color: #000000"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(209, 231, 179); color: black;" title="Background color: #d1e7b3"&gt;&lt;span title="Foreground color: #000000"&gt;+1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(215, 234, 189); color: black;" title="Background color: #d7eabd"&gt;&lt;span title="Foreground color: #000000"&gt;+2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(229, 242, 211); color: #32392a;" title="Background color: #e5f2d3"&gt;&lt;span title="Foreground color: #32392a"&gt;+3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(241, 248, 233); color: #32392a;" title="Background color: #f1f8e9"&gt;&lt;span title="Foreground color: #32392a"&gt;+4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(250, 253, 247); color: #32392a;" title="Background color: #fafdf7"&gt;&lt;span title="Foreground color: #32392a"&gt;+5&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(12, 11, 14); color: #bab6c7;" title="Background color: #0c0b0e"&gt;&lt;span title="Foreground color: #bab6c7"&gt;-5&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(29, 27, 36); color: #dcdae3;" title="Background color: #1d1b24"&gt;&lt;span title="Foreground color: #dcdae3"&gt;-4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(58, 54, 71); color: white;" title="Background color: #3a3647"&gt;&lt;span title="Foreground color: #ffffff"&gt;-3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(87, 80, 107); color: white;" title="Background color: #57506b"&gt;&lt;span title="Foreground color: #ffffff"&gt;-2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(99, 91, 121); color: white;" title="Background color: #635b79"&gt;&lt;span title="Foreground color: #ffffff"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(116, 107, 142); color: white;" title="Background color: #746B8E"&gt;&lt;span title="Foreground color: #ffffff"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(137, 129, 159); color: black;" title="Background color: #89819f"&gt;&lt;span title="Foreground color: #000000"&gt;+1&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(151, 144, 171); color: black;" title="Background color: #9790ab"&gt;&lt;span title="Foreground color: #000000"&gt;+2&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(186, 182, 199); color: black;" title="Background color: #bab6c7"&gt;&lt;span title="Foreground color: #000000"&gt;+3&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(220, 218, 227); color: #1d1b24;" title="Background color: #dcdae3"&gt;&lt;span title="Foreground color: #1d1b24"&gt;+4&lt;/span&gt;&lt;/div&gt;&lt;div class="swatch" style="background: none repeat scroll 0% 0% rgb(242, 241, 244); color: #3a3647;" title="Background color: #f2f1f4"&gt;&lt;span title="Foreground color: #3a3647"&gt;+5&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="padding-top: 0.5em;"&gt;To define these colors in our CSS file, simply add the following lines:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;pre class="code"&gt;&amp;lt;?php
include_once("csscolor.php");
$base = new CSS_Color('C9E3A6');
$highlight = new CSS_Color('746B8E');
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Then to use the colors, do something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="code"&gt;/* Use the base color, two shades darker */
background:#&amp;lt;?= $base-&amp;gt;bg['-2'] ?&amp;gt;;
/* Use the corresponding foreground color */
color:#&amp;lt;?= $base-&amp;gt;fg['-2'] ?&amp;gt;;
/* Use the highlight color as a border */
border:5px solid #&amp;lt;?= $highlight-&amp;gt;bg['0'] ?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% rgb(151, 170, 125); border: 5px solid rgb(116, 107, 142); color: black; padding: 5px;"&gt;Here is an example of the style in action.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-3745592648791648605?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/Oy4wmTrFTps" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/3745592648791648605/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/css-colors-take-control-using-php.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/3745592648791648605?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/3745592648791648605?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/Oy4wmTrFTps/css-colors-take-control-using-php.html" title="CSS Colors: Take Control Using PHP" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/css-colors-take-control-using-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEABQn07fip7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-8517771884323892844</id><published>2010-10-05T05:50:00.000-07:00</published><updated>2010-10-06T06:45:53.306-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:45:53.306-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="css" /><title>Learn CSS Positioning in Ten Steps</title><content type="html">his tutorial examines the different layout properties available in CSS: position:static, position:relative, position:absolute, and float&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;1. position:static&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The default positioning for all elements is position:static, which means the element is not positioned and occurs where it normally would in the document.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
Normally you wouldn't specify this unless you needed to override a positioning that had been previously set.&lt;br /&gt;
&lt;pre&gt;#div-1 {
 position:static;
}&amp;nbsp;&lt;/pre&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsaFNKiggI/AAAAAAAACUk/UVLso4xSIZM/s1600/10-5-2010+5-25-22+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="211" src="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsaFNKiggI/AAAAAAAACUk/UVLso4xSIZM/s320/10-5-2010+5-25-22+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;2. position:relative&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you specify position:relative, then you can use top or bottom, and left or right to move the element relative to where it would normally occur in the document.&lt;br /&gt;
&lt;br /&gt;
Let's move div-1 down 20 pixels, and to the left 40 pixels:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1 {
 position:relative;
 top:20px;
 left:-40px;
}
&lt;/pre&gt;&lt;br /&gt;
Notice the space where div-1 normally would have been if we had not moved it: now it is an empty space. The next element (div-after) did not move when we moved div-1. That's because div-1 still occupies that original space in the document, even though we have moved it.&lt;br /&gt;
&lt;br /&gt;
It appears that position:relative is not very useful, but it will perform an important task later in this tutorial.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://3.bp.blogspot.com/_T0w7K9AItgc/TKsanoFOrOI/AAAAAAAACUo/pZ-KMBhF3lI/s1600/10-5-2010+5-29-08+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="194" src="http://3.bp.blogspot.com/_T0w7K9AItgc/TKsanoFOrOI/AAAAAAAACUo/pZ-KMBhF3lI/s320/10-5-2010+5-29-08+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;3. position:absolute&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
When you specify position:absolute, the element is removed from the document and placed exactly where you tell it to go.&lt;br /&gt;
&lt;br /&gt;
Let's move div-1a to the top right of the page:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1a {
 position:absolute;
 top:0;
 right:0;
 width:200px;
}
&lt;/pre&gt;&lt;br /&gt;
Notice that this time, since div-1a was removed from the document, the other elements on the page were positioned differently: div-1b, div-1c, and div-after moved up since div-1a was no longer there.&lt;br /&gt;
&lt;br /&gt;
Also notice that div-1a was positioned in the top right corner of the page. It's nice to be able to position things directly the page, but it's of limited value.&lt;br /&gt;
&lt;br /&gt;
What I really want is to position div-1a relative to div-1. And that's where relative position comes back into play.&lt;br /&gt;
Footnotes&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt; There is a bug in the Windows IE browser: if you specify a relative width (like "width:50%") then the width will be based on the parent element instead of on the positioning element.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;4. position:relative + position:absolute&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If we set relative positioning on div-1, any elements within div-1 will be positioned relative to div-1. Then if we set absolute positioning on div-1a, we can move it to the top right of div-1:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1 {
 position:relative;
}
#div-1a {
 position:absolute;
 top:0;
 right:0;
 width:200px;
}&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://2.bp.blogspot.com/_T0w7K9AItgc/TKsbuhtSOrI/AAAAAAAACUs/bWCiOmxVwxE/s1600/10-5-2010+5-33-34+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="163" src="http://2.bp.blogspot.com/_T0w7K9AItgc/TKsbuhtSOrI/AAAAAAAACUs/bWCiOmxVwxE/s320/10-5-2010+5-33-34+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;5. two column absolute&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now we can make a two-column layout using relative and absolute positioning!&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1 {
 position:relative;
}
#div-1a {
 position:absolute;
 top:0;
 right:0;
 width:200px;
}
#div-1b {
 position:absolute;
 top:0;
 left:0;
 width:200px;
}
&lt;/pre&gt;&lt;br /&gt;
One advantage to using absolute positioning is that we can position the elements in any order on the page, regardless of the order they appear in the HTML. So I put div-1b before div-1a.&lt;br /&gt;
&lt;br /&gt;
But wait - what happened to the other elements? They are being obscured by the absolutely positioned elements. What can we do about that?&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://3.bp.blogspot.com/_T0w7K9AItgc/TKscvFbFzLI/AAAAAAAACUw/URD8mNC_Ubk/s1600/10-5-2010+5-38-12+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="140" src="http://3.bp.blogspot.com/_T0w7K9AItgc/TKscvFbFzLI/AAAAAAAACUw/URD8mNC_Ubk/s320/10-5-2010+5-38-12+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;6. two column absolute height&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
One solution is to set a fixed height on the elements.&lt;br /&gt;
&lt;br /&gt;
But that is not a viable solution for most designs, because we usually do not know how much text will be in the elements, or the exact font sizes that will be used.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1 {
 position:relative;
 height:250px;
}
#div-1a {
 position:absolute;
 top:0;
 right:0;
 width:200px;
}
#div-1b {
 position:absolute;
 top:0;
 left:0;
 width:200px;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsdHzzf4tI/AAAAAAAACU0/nfrZB3NmFFI/s1600/10-5-2010+5-39-59+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="230" src="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsdHzzf4tI/AAAAAAAACU0/nfrZB3NmFFI/s320/10-5-2010+5-39-59+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;7. float&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
For variable height columns, absolute positioning does not work, so let's come up with another solution.&lt;br /&gt;
&lt;br /&gt;
We can "float" an element to push it as far as possible to the right or to the left, and allow text to wrap around it. This is typically used for images, but we will use it for more complex layout tasks (because it's the only tool we have).&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1a {
 float:left;
 width:200px;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsde2g1x4I/AAAAAAAACU4/5tQ-QHlgixs/s1600/10-5-2010+5-41-15+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="194" src="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsde2g1x4I/AAAAAAAACU4/5tQ-QHlgixs/s320/10-5-2010+5-41-15+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;8. float columns&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If we float one column to the left, then also float the second column to the left, they will push up against each other.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1a {
 float:left;
 width:150px;
}
#div-1b {
 float:left;
 width:150px;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://3.bp.blogspot.com/_T0w7K9AItgc/TKsd1H5CFNI/AAAAAAAACU8/QMQgibXleSg/s1600/10-5-2010+5-43-05+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="204" src="http://3.bp.blogspot.com/_T0w7K9AItgc/TKsd1H5CFNI/AAAAAAAACU8/QMQgibXleSg/s320/10-5-2010+5-43-05+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;9. float columns with clear&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Then after the floating elements we can "clear" the floats to push down the rest of the content.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#div-1a {
 float:left;
 width:190px;
}
#div-1b {
 float:left;
 width:190px;
}
#div-1c {
 clear:both;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;a href="http://2.bp.blogspot.com/_T0w7K9AItgc/TKseTEVkYnI/AAAAAAAACVA/MIY67xp-GQs/s1600/10-5-2010+5-44-59+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="218" src="http://2.bp.blogspot.com/_T0w7K9AItgc/TKseTEVkYnI/AAAAAAAACVA/MIY67xp-GQs/s320/10-5-2010+5-44-59+PM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;10. Disclaimer &amp;amp; Resources&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
These examples are extremely simplified and do not trigger some of the CSS bugs in the Windows IE browser (of which there are many).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-8517771884323892844?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/rkr7MTUALYw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/8517771884323892844/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/learn-css-positioning-in-ten-steps.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8517771884323892844?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8517771884323892844?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/rkr7MTUALYw/learn-css-positioning-in-ten-steps.html" title="Learn CSS Positioning in Ten Steps" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_T0w7K9AItgc/TKsaFNKiggI/AAAAAAAACUk/UVLso4xSIZM/s72-c/10-5-2010+5-25-22+PM.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/learn-css-positioning-in-ten-steps.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE8ERH85fCp7ImA9Wx5VE0o.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-972392888018738459</id><published>2010-10-05T05:23:00.000-07:00</published><updated>2010-10-06T06:46:45.124-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-06T06:46:45.124-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="css" /><title>Simple 2 column CSS layout</title><content type="html">This is a tutorial on how to use CSS to create a simple two column layout.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The layout consists of a header, a horizontal navigation bar, a main content column, a sidebar, and a footer. It is also horizontally centered in the browser window. A pretty basic layout, and not at all difficult to create with CSS once you know how to deal with the inevitable Internet Explorer bugs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To see the full CSS used for each step, view source on the example documents.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;1. Basic structure&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we create the basic HTML structure:&lt;br /&gt;
&lt;pre&gt;&amp;lt;div id="wrap"&amp;gt;
&amp;lt;div id="header"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div id="nav"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div id="main"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div id="sidebar"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div id="footer"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
After that, we put some content in the different sections:&lt;br /&gt;
&lt;pre&gt;&amp;lt;div id="wrap"&amp;gt;
&amp;lt;div id="header"&amp;gt;
&amp;lt;h1&amp;gt;Document Heading&amp;lt;/h1&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div id="nav"&amp;gt;
&amp;lt;ul&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Option 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Option 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div id="main"&amp;gt;
&amp;lt;h2&amp;gt;Column 1&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit...&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div id="sidebar"&amp;gt;
&amp;lt;h2&amp;gt;Column 2&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit...&amp;lt;/p&amp;gt;
&amp;lt;ul&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Link 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Link 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div id="footer"&amp;gt;
&amp;lt;p&amp;gt;Footer&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Now we have a completely unstyled HTML document which is structured in a way that lets us use CSS to control its layout.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;2. Adjust the body and html elements&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
To make the content reach the edges of the browser window, we set the margin and padding of the body and html elements to zero. We also specify colours for text and background.&lt;br /&gt;
&lt;pre&gt;body,
    html {
    margin:0;
    padding:0;
    color:#000;
 background:#a7a09a;
 }
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;3. On to the main containers&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
After that it’s time to give the content area a width and center it horizontally. We do that by specifying the width and margins of the main container, #wrap. We also give it a background colour to make it show up on the page.&lt;br /&gt;
&lt;br /&gt;
The method we use to center the content is based on the fact that when an element’s left and right margins are set to auto, they will share whatever is left when the element’s width has been subtracted from that of its container. In this case the width of #wrap will be subtracted from the width of the browser window.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#wrap {
  width:750px;
  margin:0 auto;
  background:#99c;
}
&lt;/pre&gt;&lt;br /&gt;
In case you’re wondering why we’re not using the body element to control the width and centering of the layout, it is because doing so can cause unwanted side-effects in some versions of Internet Explorer.&lt;br /&gt;
&lt;br /&gt;
After that, we give the different sections of the document different background colours to make them show up.&lt;br /&gt;
&lt;pre&gt;#header {
   background:#ddd;
   }
#nav {
   background:#c99;
}
#main {
   background:#9c9;
}
#sidebar {
  background:#c9c;
}
#footer {
  background:#cc9;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;4. Place the columns side by side&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To make the two columns (#main and #sidebar) display side by side we float them, one to the left and the other to the right. We also specify the widths of the columns.&lt;br /&gt;
&lt;pre&gt;#main {
   float:left;
   width:500px;
   background:#9c9;
}
#sidebar {
   float:right;
   width:250px;
   background:#c9c;
}
&lt;/pre&gt;Note that the sum of the widths should be equal to the width given to #wrap in Step 3.&lt;br /&gt;
&lt;br /&gt;
This will make #sidebar appear to the right of #main, but the footer is not where it should be.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;5. Push the footer down&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The footer doesn’t get pushed down to the bottom of the content because of the way float works. When you float an element, it is removed from the document flow and doesn’t push elements that follow it down. In this case #footer will start right below #sidebar.&lt;br /&gt;
&lt;br /&gt;
To avoid this we use the clear property to tell the footer that it can’t have any elements next to it.&lt;br /&gt;
&lt;pre&gt;#footer {
   clear:both;
   background:#cc9;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;6. Fix the background colour&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now we can see that the shorter column doesn’t continue all the way down to the footer. To make it look like it does, we use the same background colour for #sidebar and #wrap.&lt;br /&gt;
&lt;pre&gt;#sidebar {
   float:right;
   width:250px;
   background:#99c;
}
&lt;/pre&gt;&lt;br /&gt;
Also, if you take a look at this step in Internet Explorer 6 you may notice that the background colour of the footer is pushing up beside the main content. That will be taken care of later.&lt;br /&gt;
&lt;br /&gt;
If you don't know which column is going to be the tallest, and you want both columns to have different backgrounds and look like they are going all the way to the bottom, you need to use a workaround. There are several ways to achieve that effect:&lt;br /&gt;
&lt;a href="http://www.alistapart.com/articles/fauxcolumns/"&gt;Faux Columns&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.alistapart.com/articles/negativemargins/"&gt;Creating Liquid Layouts with Negative Margins&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.positioniseverything.net/articles/onetruelayout/"&gt;In search of the One True Layout&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;7. Make the navigation bar horizontal&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
#nav contains a regular unordered list of links. Since we don’t want it to look like an unordered list we restyle it.&lt;br /&gt;
&lt;pre&gt;#nav ul {
   margin:0;
   padding:0;
   list-style:none;
}
#nav li {
   display:inline;
   margin:0;
   padding:0;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;8. Adjust margins and paddings, and make IE 6 cooperate&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Almost done. Time to adjust the margin and padding of some elements to make the layout a little less cramped.&lt;br /&gt;
&lt;pre&gt;#header {
   padding:5px 10px;
   background:#ddd;
}
h1 {
   margin:0;
}
#nav {
   padding:5px 10px;
   background:#c99;
}
#main {
   float:left;
   width:480px;
   padding:10px;
   background:#9c9;
}
h2 {
   margin:0 0 1em;
}
#sidebar {
   float:right;
   width:230px;
   padding:10px;
   background:#99c;
}
#footer {
   clear:both;
   padding:5px 10px;
   background:#cc9;
}
#footer p {
   margin:0;
}
&lt;/pre&gt;&lt;br /&gt;
One thing to take note of here is that when we added padding to #main and #sidebar, we subtracted the width of the left and right paddings from each element’s width. This is how the CSS box model works&lt;br /&gt;
&lt;br /&gt;
And the final thing is to compensate for a float bug in Internet Explorer 6. If you look at step 6 in IE 6, you’ll notice that the footer is not always being pushed completely below #main. Scroll up and down a couple of times if you can’t see it immediately.&lt;br /&gt;
&lt;br /&gt;
It is very noticeable in this demo because every major element has a different background colour and everything is really tight. One way of fixing this problem is making sure the footer has an Internet Explorer concept called Layout. There are several ways of achieving this, but we’ll do it by using the Star HTML CSS hack to give the footer a height only in IE 6:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;* html #footer {
  height:1px;
}
&lt;/pre&gt;&lt;br /&gt;
As strange as it may look, this does the job. Thanks to another bug in IE, the footer will not be just one pixel tall, but as tall as its content dictates.&lt;br /&gt;
&lt;br /&gt;
Please don’t hesitate to contact me if you can suggest improvements to this method.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-972392888018738459?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/Mbs5dvSzuuc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/972392888018738459/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/10/simple-2-column-css-layout.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/972392888018738459?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/972392888018738459?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/Mbs5dvSzuuc/simple-2-column-css-layout.html" title="Simple 2 column CSS layout" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/10/simple-2-column-css-layout.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8AR3s_fip7ImA9Wx5WF0k.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-1054273311876562349</id><published>2010-09-28T23:21:00.000-07:00</published><updated>2010-09-29T00:20:46.546-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-29T00:20:46.546-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Installation" /><title>Installing Windows 2000 Professional</title><content type="html">To install Windows 2000 Professional, follow these steps:  &lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Start the installation by using one of the following methods:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Start  from the Windows 2000 Professional installation CD-ROM. Make sure that the CD-ROM is set to start before the hard disk starts.  Insert the CD-ROM, and then when you are prompted, press any key to  start the Windows 2000 Professional Setup program. &lt;/li&gt;
&lt;li&gt;Start from  boot disks. Insert Disk 1, and then insert each of the remaining three  floppy disks when you are prompted to do so. For additional information  about creating boot disks for Windows 2000&lt;/li&gt;
&lt;li&gt;Start from within a current operating system. Insert the CD-ROM, and then, at a command prompt, type &lt;span class="userInput"&gt;&lt;var&gt;drive&lt;/var&gt;:\i386\winnt32.exe&lt;/span&gt; and then press ENTER, or if this is an installation on a computer that has no previous installation of Windows, type &lt;span class="userInput"&gt;&lt;var&gt;drive&lt;/var&gt;:\i386\winnt.exe&lt;/span&gt; and then press ENTER, where &lt;var&gt;drive&lt;/var&gt; is the letter of the CD-ROM drive.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Setup inspects your computer's hardware configuration and then begins to install the Setup and driver files. When the &lt;b&gt;Microsoft Windows 2000 Professional&lt;/b&gt; screen appears, press ENTER to set up Windows 2000 Professional.&lt;/li&gt;
&lt;li&gt;Read  the license agreement, and then press the F8 key to accept the terms of  the license agreement and continue the installation.&lt;/li&gt;
&lt;li&gt;When the &lt;b&gt;Windows 2000 Professional Setup&lt;/b&gt;  screen appears, either press ENTER to set up Windows 2000 Professional  on the selected partition, or press C to create a partition in the  unpartitioned space.&lt;/li&gt;
&lt;li&gt;If you choose to install Windows 2000 Professional on a file allocation table (FAT) partition, specify whether you want to:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Leave the current file system intact.&lt;/li&gt;
&lt;li&gt;Format the partition as FAT16.&lt;/li&gt;
&lt;li&gt;Convert the existing file system to the NTFS file system.&lt;/li&gt;
&lt;li&gt;Format the partition by using the NTFS file system.&lt;/li&gt;
&lt;/ul&gt;Press ENTER after you make your selection. Setup examines the existing  hard disks and then copies the files that are needed to complete the  installation of Windows 2000 Professional. After the files are copied,  the computer restarts.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Important&lt;/b&gt; Do not press a key to boot from your CD-ROM drive when your computer restarts. &lt;/li&gt;
&lt;li&gt;When the Windows 2000 GUI Mode Setup Wizard appears, click &lt;b&gt;Next&lt;/b&gt; to start the wizard. Setup detects and installs such devices as a specialized mouse or keyboard.&lt;/li&gt;
&lt;li&gt;When the &lt;b&gt;Regional Options&lt;/b&gt;  dialog box appears, customize your installation of Windows 2000  Professional for locale, number format, currency, time, date, and  language, if necessary. Click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;b&gt;Personalize Your Software&lt;/b&gt; dialog box, type your name and the name of your organization, and then click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;b&gt;Product ID&lt;/b&gt; dialog box, type the 25-character product key, and then click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;b class="uiterm"&gt;Computer Name and Password&lt;/b&gt;  dialog box, either accept the default name that Setup generates or  assign a different name for the computer. When you are prompted for an  administrative password, type a password for the Administrator account.  (You can leave the box blank; however, this is not recommended.) Click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;b class="uiterm"&gt;Date and Time Settings&lt;/b&gt;  dialog box, set the correct date and time for your computer. You can  also specify which time zone you are in and set the computer to  automatically adjust the clock for daylight saving time. Click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Setup installs the networking software and detects your network settings. When the &lt;b&gt;Network Settings&lt;/b&gt; dialog box appears, click either&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Typical&lt;/b&gt;  to set default network settings such as File and Print Sharing for  Microsoft Networks, Client for Microsoft Networks, and TCP/IP protocol  that uses Dynamic Host Configuration Protocol (DHCP), or&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Custom&lt;/b&gt; to specify the network components that you require for your network environment,&lt;/li&gt;
&lt;/ul&gt;and then click &lt;b&gt;Next&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;In the &lt;b class="uiterm"&gt;Workgroup or Computer Domain&lt;/b&gt;  dialog box, specify the workgroup or the domain to join. If you  indicate that you are part of a domain, specify your domain user name  and password. Click &lt;b&gt;Next&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Setup installs the networking components. &lt;/li&gt;
&lt;li&gt;During the final  stage of installation, Setup installs Start menu items, registers  components, saves settings, and removes temporary files. When the &lt;b class="uiterm"&gt;Completing the Windows 2000 Setup Wizard&lt;/b&gt; dialog box prompts you to do so, remove the Windows 2000 CD-ROM, and then click &lt;b&gt;Finish&lt;/b&gt; to restart the computer.  &lt;/li&gt;
&lt;li&gt;After the computer restarts, click &lt;b&gt;Next&lt;/b&gt; in the &lt;b class="uiterm"&gt;Welcome to the Network Identification Wizard&lt;/b&gt; dialog box.&lt;/li&gt;
&lt;li&gt;In the &lt;b class="uiterm"&gt;Users of This Computer&lt;/b&gt;  dialog box, specify either that users must enter a user name and  password or that you want Windows 2000 to automatically log on a  specific user when the computer starts. Click &lt;b&gt;Finish&lt;/b&gt;.&lt;/li&gt;
&lt;/ol&gt;When the Windows 2000 Professional desktop appears, the installation is complete.&lt;br /&gt;
&lt;br /&gt;
&lt;!-- BEGIN: Shopzilla Publisher Asset HTML --&gt;&lt;br /&gt;
&lt;div style="background-color: #FFFFFF;border: 0px solid #000000;font-family: Arial, Sans-serif;font-size: 10px;padding: 0px 0px 0px 0px;line-height: 11px;color: #000000;width: 468px;height: 60px;"&gt;&lt;br /&gt;
&lt;iframe width="468" vspace="0" scrolling="no" src="https://adserve.shopzilla.com/pp/content/tal/publisherID-36586/assetID-353/assetTypeID-9/placementID-1/showProducts-3/showRandom-0/start-1/sort-default/onlyOffers-1/categoryID-18000000/tokenID-7X/style-10px%20Arial%2C%20Sans-serif;000000:FFFFFF:0A4E97:0A4E97:006600:666666:FFFFFF;0px%20solid;_blank" name="display" height="60" marginwidth="0" hspace="0" frameborder="0" marginheight="0"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;div xmlns:tal="http://xml.zope.org/namespaces/tal" style="width: 448px;height: 10px;border: 0px;"&gt;&lt;div style="text-align: right;display: block;float: right;padding-right: 2px;color:#5E5A80;font-size:10px;"&gt;Shop more  at &lt;a href="http://www.bizrate.com/index__rf--af1__af_id--36586__af_creative_id--353__af_assettype_id--9__af_placement_id--1.html" target="_blank" style="font-size: 10px; color:#666666;"&gt;Bizrate&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;noscript&gt;&lt;a href="https://adserve.bizrate.com/pp/content/tal/publisherID-36586/assetID-353/assetTypeID-9/placementID-1/showProducts-3/showRandom-0/start-1/sort-default/cache-1/noLog-1/standAlone-1/onlyOffers-1/categoryID-18000000/tokenID-7X/style-"&gt;Bizrate&lt;/a&gt;&lt;/NOSCRIPT&gt;&lt;br /&gt;
&lt;!-- END: Shopzilla Publisher Asset HTML --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-1054273311876562349?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/6vPLD0oxIjM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/1054273311876562349/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/installing-windows-2000-professional.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/1054273311876562349?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/1054273311876562349?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/6vPLD0oxIjM/installing-windows-2000-professional.html" title="Installing Windows 2000 Professional" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/installing-windows-2000-professional.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcDRnw6fCp7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-1161357758842161830</id><published>2010-09-27T04:30:00.000-07:00</published><updated>2010-09-27T04:31:17.214-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T04:31:17.214-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Using Associative Arrays for Client-side Caching using AJAX &amp; Javascript</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;img src="http://www.codeproject.com/KB/ajax/Client-sideCaching/article2.gif" /&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This article shows you a useful technique to cache some of that page data on the browser in-memory. Since we use Ajax, the page is not reloaded each time. This prevents the cache from being invalidated on each round-trip. Client-side caching is sometimes required for performance reasons and also to take the load off of the DBMS. Since most modern PCs have plenty of RAM to spare, client-side caching becomes an important weapon in the modern programmer's arsenal of tricks.&lt;br /&gt;
&lt;br /&gt;
With the advent of Ajax, application data can be maintained on the client without the use of ViewStates (aka hidden fields) or to a lesser degree, cookies. As any experienced developer will tell you, ViewState is a double-edged sword. Indiscriminate use of ViewStates can really have a detrimental effect on performance - what with the Viewstate payload ferried to and from the server with every postback.&lt;br /&gt;
&lt;br /&gt;
The accompanying code can be extended to use record data too, via Javascript and         the presentation logic can also be hived off to a Javascript routine on the client.         We could even pipe XML down to the client and it could be parsed and presented through         client-side script.&lt;br /&gt;
&lt;br /&gt;
To keep this sample         code easy to comprehend, I have rendered the tabular data from within the Web Service         itself - which may not be architecturally optimal. Since this is not a treatise         on design best-practices, I have taken the liberty of cutting corners here and there for the sake of brevity.     &lt;br /&gt;
&lt;br /&gt;
img width="36" height="42" style="float: left;" alt="Screenshot - article1.gif" src="Client-sideCaching/article1.gif" /&amp;gt;We             use JavaScript associative arrays to maintain our client-side cache. One thing to             be noted about JS associative arrays is that once you associate a string key with             an array, there is no way to iterate through the array using indexes. Supposing             you are using it like this:&lt;code&gt;asarray[&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;akey"&lt;/span&gt;] = &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;value&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt; there is no             way you can revert to accessing the elements by their ordinal position like this:             &lt;code&gt;var anyvar = asarray[&lt;span class="code-digit"&gt;0&lt;/span&gt;]&lt;/code&gt;.     &lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h2&gt;Using the code&lt;/h2&gt;Let us examine the critical sections of the code that are absolutely necessary for     client-side caching to work. The rest of the code deals with presentation and layout     and a discussion on these aspects will be skipped.&lt;br /&gt;
For those who subscribe to the view that source-code is the ultimate documentation,     you may skip this section. For the others, we'll try to separate the wheat from     the chaff. Let us look at the most important pieces of code that makes client-side caching with Ajax and     Javascript possible. I am using XML data for demonstration purposes and this makes the project run without     having to change connection strings or even having SQL Server installed on your computer.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Step 1&lt;/h2&gt;Create a New Website and choose "ASP.NET AJAX-Enabled Website". If you do not have .NET 2.0 Ajax Toolkit     installed, go &lt;a href="http://www.asp.net/"&gt;here&lt;/a&gt; and download them. You cannot begin this exercise without it.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Step 2&lt;/h2&gt;Select "Add New Item" by right-clicking on the project in Solution Explorer and choose "Web Service".     Add the highlighted code to your web service class.      The &lt;code&gt;[ScriptService]&lt;/code&gt; attribute decoration makes the web service class     callable by the Ajax framework. You have to include &lt;code&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System.Web.Script.Services&lt;/code&gt; to      be able to do that.     &lt;br /&gt;
&lt;pre id="pre0" lang="cs" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System.Web.Script.Services;
...
[ScriptService] 
    &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;class&lt;/span&gt; DataAccess : System.Web.Services.WebService 
    { ...&lt;/pre&gt;&lt;pre id="pre0" lang="cs" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;h2&gt;Step 3&lt;/h2&gt;Flesh out your web method to do something useful. Our example does this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="cs" style="margin-top: 0pt;"&gt;[WebMethod]
&lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;string&lt;/span&gt; FetchOrders(&lt;span class="code-keyword"&gt;string&lt;/span&gt; key)
{           
    &lt;span class="code-keyword"&gt;return&lt;/span&gt; LoadData(key);;
}

&lt;span class="code-keyword"&gt;private&lt;/span&gt; &lt;span class="code-keyword"&gt;string&lt;/span&gt; LoadData(&lt;span class="code-keyword"&gt;string&lt;/span&gt; key)
{        
    DataSet ds = &lt;span class="code-keyword"&gt;new&lt;/span&gt; DataSet();
    ds.ReadXml(&lt;span class="code-keyword"&gt;this&lt;/span&gt;.Context.Server.MapPath(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;App_Data\\northwind.xml"&lt;/span&gt;));
    ds.Tables[&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Orders"&lt;/span&gt;].DefaultView.RowFilter = &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;customerid = '"&lt;/span&gt; + key + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;'"&lt;/span&gt;;        
    &lt;span class="code-keyword"&gt;return&lt;/span&gt; RenderResultTable((ds.Tables[&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Orders"&lt;/span&gt;].DefaultView));
}

&lt;span class="code-keyword"&gt;private&lt;/span&gt; &lt;span class="code-keyword"&gt;string&lt;/span&gt; RenderResultTable(DataView rdr)
{
    StringBuilder str = &lt;span class="code-keyword"&gt;new&lt;/span&gt; StringBuilder();
    str.AppendLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt;

&lt;table cellborder="\&amp;quot;=0\&amp;quot;" cellpadding="\&amp;quot;5\&amp;quot;" cellspacing="\&amp;quot;0\&amp;quot;"&gt;&lt;span class="code-string"&gt;");     str.AppendLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt;&lt;/span&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Order Date&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Order ID&lt;/b&gt;         &lt;/td&gt;&lt;/tr&gt;
&lt;span class="code-string"&gt;");     &lt;span class="code-keyword"&gt;foreach&lt;/span&gt;(DataRowView drv &lt;span class="code-keyword"&gt;in&lt;/span&gt; rdr)     {         str.AppendLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt; &lt;/span&gt;
&lt;tr&gt;&lt;span class="code-string"&gt;");         str.AppendFormat(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt;&lt;/span&gt;&lt;td&gt;{0}&lt;/td&gt; &lt;td&gt;{1}&lt;/td&gt;&lt;span class="code-string"&gt;", drv[&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;OrderDate"&lt;/span&gt;],              drv[&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;OrderID"&lt;/span&gt;]);         str.AppendLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tr&gt;
&lt;span class="code-string"&gt;");     }     str.AppendLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="code-string"&gt;"&lt;/span&gt;);
    &lt;span class="code-keyword"&gt;return&lt;/span&gt; str.ToString();
}&lt;/pre&gt;&lt;br /&gt;
&lt;h2&gt;Step 4&lt;/h2&gt;Now, we go to the client script that does the actual caching and retrieves data by making a call     to the web service. This employs rudimentary JavaScript - no surprises here.&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre2" lang="cs" style="margin-top: 0pt;"&gt;var cacheData = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Array(); &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; This is our cache
&lt;/span&gt;
var currSel = &lt;span class="code-keyword"&gt;null&lt;/span&gt;;
var seedData = &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;0BFA4D6B-DD18-48aa-A926-B9FD80BFA5B7"&lt;/span&gt;;   
&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; Prime a cache item with a unique initial value&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;h2&gt;Step 5&lt;/h2&gt;Add the needed JavaScript code now. We have a HTML button with the ID &lt;code&gt;btnFetch&lt;/code&gt;.      In the OnClick event, we trigger either an Ajax asynchronous call to the server or render      from the cache.&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre3" lang="cs" style="margin-top: 0pt;"&gt;function btnFetch_onclick() 
{    
    currSel = document.getElementById(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;dlCustomers"&lt;/span&gt;).value;    
    var status = document.getElementById(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;divStatus"&lt;/span&gt;);
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;var svc = new DataAccess();
&lt;/span&gt;

    &lt;span class="code-keyword"&gt;if&lt;/span&gt;(cacheData[currSel]==null)
    {
        DataAccess.FetchOrders(currSel,OnCompleteCallback,OnErrorCallback, 
            OnTimeOutCallback);   
        cacheData[currSel] = seedData;         
        status.innerHTML = &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;[Live Result]"&lt;/span&gt;;
    }
    &lt;span class="code-keyword"&gt;else&lt;/span&gt;
    {                
        status.innerHTML = &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;[Cached Result]"&lt;/span&gt;;        
        var cacheobject = FetchDataFromCache(currSel);
        RenderData(cacheobject);
    }
    document.getElementById(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;dlCustomers"&lt;/span&gt;).focus();    
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-1161357758842161830?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/nsGhw8Q0GbE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/1161357758842161830/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/using-associative-arrays-for-client.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/1161357758842161830?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/1161357758842161830?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/nsGhw8Q0GbE/using-associative-arrays-for-client.html" title="Using Associative Arrays for Client-side Caching using AJAX &amp; Javascript" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/using-associative-arrays-for-client.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEESXc_eSp7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-8621066904143198921</id><published>2010-09-27T04:22:00.000-07:00</published><updated>2010-09-27T04:23:28.941-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T04:23:28.941-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Calling Server Side Code from Client Side using Ajax</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;Using Microsoft ASP.NET AJAX is to call ASP.NET Web services (&lt;i&gt;*.asmx&lt;/i&gt;  files) from the browser by using client script. The script can call a  webservice containing server-based methods (Web methods) and invoke  these methods without a postback and without refreshing the whole page.  The option we are going to use in this article involves &lt;code&gt;PageMethods&lt;/code&gt;. A &lt;code&gt;PageMethod &lt;/code&gt;is basically a &lt;code&gt;&lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;/code&gt;method that is exposed in the code-behind of an aspx page and is callable from the client script. &lt;code&gt;PageMethods&lt;/code&gt; are annotated with the &lt;code&gt;[WebMethod]&lt;/code&gt; attribute. The page methods are rendered as inline JavaScript&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h2&gt;Step 1&lt;/h2&gt;Create an ASP.NET AJAX enabled website. Go to File &amp;gt; New &amp;gt;  Website &amp;gt; ASP.NET AJAX-Enabled Web Site. Give the solution a name and  location and click Ok.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Step 2&lt;/h2&gt;Drag and drop label and textbox controls. We will be accepting the &lt;code&gt;CustomerID &lt;/code&gt;from the user in the textbox and displaying the ‘&lt;code&gt;ContactName&lt;/code&gt;’ in the label Add the connection string in Config section tag in &lt;i&gt;web.config&lt;/i&gt; file.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Step 3&lt;/h2&gt;Currently we will add a method, ‘&lt;code&gt;GetContactName()&lt;/code&gt;’ which will accept a &lt;code&gt;CustomerID &lt;/code&gt;and return the Contact Name information from the Northwind database, &lt;code&gt;Customer &lt;/code&gt;table. We will then transform this method as a &lt;code&gt;PageMethod&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre0" lang="cs" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;string&lt;/span&gt; GetContactName(&lt;span class="code-keyword"&gt;string&lt;/span&gt; custid) 
{ 
&lt;span class="code-keyword"&gt;if&lt;/span&gt; (custid == &lt;span class="code-keyword"&gt;null&lt;/span&gt; || custid.Length == &lt;span class="code-digit"&gt;0&lt;/span&gt;) 
&lt;span class="code-keyword"&gt;return&lt;/span&gt; &lt;span class="code-SDKkeyword"&gt;String&lt;/span&gt;.Empty; 
SqlConnection conn = &lt;span class="code-keyword"&gt;null&lt;/span&gt;; 
&lt;span class="code-keyword"&gt;try&lt;/span&gt; 
{ 
&lt;span class="code-keyword"&gt;string&lt;/span&gt; connection = ConfigurationManager.ConnectionStrings
   [&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;NorthwindConnectionString"&lt;/span&gt;].ConnectionString; 
conn = &lt;span class="code-keyword"&gt;new&lt;/span&gt; SqlConnection(connection); 
&lt;span class="code-keyword"&gt;string&lt;/span&gt; sql = &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Select ContactName from Customers where CustomerId = @CustID"&lt;/span&gt;; 
SqlCommand cmd = &lt;span class="code-keyword"&gt;new&lt;/span&gt; SqlCommand(sql, conn); 
cmd.Parameters.AddWithValue(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;CustID"&lt;/span&gt;, custid); 
conn.Open(); 
&lt;span class="code-keyword"&gt;string&lt;/span&gt; contNm = Convert.ToString(cmd.ExecuteScalar()); 
&lt;span class="code-keyword"&gt;return&lt;/span&gt; contNm; 
} 
&lt;span class="code-keyword"&gt;catch&lt;/span&gt; (SqlException ex) 
{ 
&lt;span class="code-keyword"&gt;return&lt;/span&gt; &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;error"&lt;/span&gt;; 
} 
&lt;span class="code-keyword"&gt;finally&lt;/span&gt; 
{ 
conn.Close(); 
} 
}&lt;/pre&gt;&lt;pre id="pre0" lang="cs" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;h2&gt;Step 4&lt;/h2&gt;We will now transform this method as a &lt;code&gt;PageMethod &lt;/code&gt;and then call this method &lt;code&gt;GetContactName()&lt;/code&gt; from the client side code; i.e. using JavaScript. To enable the method as a &lt;code&gt;PageMethod&lt;/code&gt;, add the attribute &lt;code&gt;[WebMethod] &lt;/code&gt;on top of the method:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="cs" style="margin-top: 0pt;"&gt;[System.Web.Services.WebMethod] 
&lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;string&lt;/span&gt; GetContactName(&lt;span class="code-keyword"&gt;string&lt;/span&gt; custid) 
{ 
}&lt;/pre&gt;&lt;pre id="pre1" lang="cs" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;At the same time, add the attribute &lt;code&gt;EnablePageMethods=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;true"&lt;/span&gt; &lt;/code&gt;to the &lt;code&gt;ScriptManager&lt;/code&gt;. &lt;br /&gt;
&lt;h2&gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;/h2&gt;Let us now create the JavaScript that will call this server side code. Add a JavaScript file called &lt;i&gt;script.js&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre2" lang="jscript" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;function&lt;/span&gt; CallMe(src,dest) 
{ 
&lt;span class="code-keyword"&gt;var&lt;/span&gt; ctrl = document.getElementById(src); 
&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; call server side method &lt;/span&gt;
PageMethods.GetContactName(ctrl.value, CallSuccess, CallFailed, dest); 
} 
&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; set the destination textbox value with the ContactName &lt;/span&gt;
&lt;span class="code-keyword"&gt;function&lt;/span&gt; CallSuccess(res, destCtrl) 
{ 
&lt;span class="code-keyword"&gt;var&lt;/span&gt; dest = document.getElementById(destCtrl); 
dest.value = res; 
} 
&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; alert message on some failure &lt;/span&gt;
&lt;span class="code-keyword"&gt;function&lt;/span&gt; CallFailed(res, destCtrl) 
{ 
alert(res.get_message()); 
}&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;
&lt;h2&gt;Step 6&lt;/h2&gt;We now need to reference this JavaScript file from our aspx page and invoke the ‘&lt;code&gt;CallMe()&lt;/code&gt;’ method whenever the textbox looses focus. To do so: Add a reference to the JavaScript file in the &lt;code&gt;body &lt;/code&gt;tag as shown below: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre3" lang="jscript" style="margin-top: 0pt;"&gt;&amp;lt;body&amp;gt; &amp;lt;script type="text/javascript" language="javascript" src="script.js"&amp;gt; 
&amp;lt;/script&amp;gt; &amp;lt;form id="form1" runat="server"&amp;gt; 
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;&lt;br /&gt;
Step 7&lt;/h2&gt;&lt;br /&gt;
To invoke the methods whenever the textbox looses focus, add these lines of code in the &lt;code&gt;Page_Load() &lt;/code&gt;event:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre4" lang="jscript" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;if&lt;/span&gt; (!Page.IsPostBack) 
{ 
txtId1.Attributes.Add(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;onblur"&lt;/span&gt;, 
    &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;javascript:CallMe('"&lt;/span&gt; + txtId1.ClientID + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;', '"&lt;/span&gt; + txtContact1.ClientID + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;')"&lt;/span&gt;); 
txtId2.Attributes.Add(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;onblur"&lt;/span&gt;, 
    &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;javascript:CallMe('"&lt;/span&gt; + txtId2.ClientID + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;', '"&lt;/span&gt; + txtContact2.ClientID + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;')"&lt;/span&gt;); 
}&lt;/pre&gt;&lt;br /&gt;
As shown above, we are using the &lt;code&gt;Attributes.Add&lt;/code&gt; that lets us add an attribute to the server control’s &lt;code&gt;System.Web.UI.AttributeCollection &lt;/code&gt;object. The function ‘&lt;code&gt;CallMe&lt;/code&gt;’ kept in the ‘&lt;i&gt;script.js&lt;/i&gt;’ file will be invoked. We are passing the source and destination textboxes as parameters. The source textbox will contain the &lt;code&gt;CustomerID&lt;/code&gt;. The &lt;code&gt;CustomerID &lt;/code&gt;will be looked up in the &lt;code&gt;Customers &lt;/code&gt;table and the corresponding ‘&lt;code&gt;ContactName&lt;/code&gt;’ will be retrieved in the destination textbox.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-8621066904143198921?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/1llxu3cRo6g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/8621066904143198921/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/calling-server-side-code-from-client.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8621066904143198921?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8621066904143198921?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/1llxu3cRo6g/calling-server-side-code-from-client.html" title="Calling Server Side Code from Client Side using Ajax" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/calling-server-side-code-from-client.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08FRHw_fCp7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-8859746966976193846</id><published>2010-09-27T04:08:00.000-07:00</published><updated>2010-09-27T04:10:15.244-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T04:10:15.244-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>A cool'n'simple search page using Google AJAX Search API, and some DHTML</title><content type="html">&lt;img src="http://www.codeproject.com/KB/ajax/CoolNSimpleGoogleAJAX/Cool-n-Simple-Google-AJAX-Search.gif" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In this article I'll demonstrate how easy it is, to create a usable webpage with some advanced technologies (such as fast asynchronous web search) in a very simple way, using a public API.&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Background&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I've created this page since I wanted:&lt;br /&gt;
&lt;br /&gt;
1. A search oriented homepage that uses google as it's engine&lt;br /&gt;
2. To be able to search and re-search without needing to point the cursor to the search field, nor use a lot of tab keystrokes&lt;br /&gt;
3. A simple way to search my blog&lt;br /&gt;
4. A cool root for my personal website &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Using the code&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Step 1: Initialization&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The first thing we are going to do, is to create a minimal webpage markup:&lt;br /&gt;
&lt;pre id="pre0" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;!DOCTYPE&lt;/span&gt; &lt;span class="code-attribute"&gt;html&lt;/span&gt; &lt;span class="code-attribute"&gt;PUBLIC&lt;/span&gt; &lt;span class="code-attribute"&gt;"-&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;W3C&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;DTD&lt;/span&gt; &lt;span class="code-attribute"&gt;XHTML&lt;/span&gt; &lt;span class="code-attribute"&gt;1.0&lt;/span&gt; &lt;span class="code-attribute"&gt;Strict&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;EN"&lt;/span&gt; 
         &lt;span class="code-attribute"&gt;"http:&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;www.w3.org&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;TR&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;xhtml1&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;DTD&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;xhtml1-strict.dtd"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;html&lt;/span&gt; &lt;span class="code-attribute"&gt;xmlns&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;head&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;meta&lt;/span&gt; &lt;span class="code-attribute"&gt;http-equiv&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;content-type"&lt;/span&gt; &lt;span class="code-attribute"&gt;content&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text/html; charset=utf-8"&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;title&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;My Cool'n'Simple Search Page&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;title&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;head&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;body&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;h1&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;My Cool'n'Simple Search Page&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;h1&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;body&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;html&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre0" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre0" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre0" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;h3&gt;Step 2: Make room&lt;/h3&gt;Now we will add a search field, and make room for the search results:&lt;br /&gt;
&lt;pre id="pre1" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;queryContainer"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;input&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text"&lt;/span&gt; &lt;span class="code-attribute"&gt;name&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;query"&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;query"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;searchcontrol"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;br&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;branding"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;Powered by Google&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;pre id="pre0" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;
&lt;/pre&gt;The query input field is wrapped in a div for styling purposes&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Step 3: Style it up a little&lt;/h3&gt;We will add some css rules in order to make our page look a little  bit nicer. We'd want a readable font, some space between the input query  and the results, a clean look for the input, and make it all at the  centered in the page &lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre2" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;style&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text/css"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
body
{
    font-family: verdana;
    text-align: center;
}
#queryContainer
{
    margin-bottom:2em;
    width: 80%;
    margin-left:auto;
    margin-right:auto;
}
#query
{
    border:1px solid silver;
    width: 100%;
}
#searchcontrol
{
    width:80%;
    margin-left:auto;
    margin-right:auto;
    text-align:left;
}
.gsc-control 
{ 
    width: 100%; 
}
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;style&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre2" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;We have also set the &lt;code&gt;gsc-control&lt;/code&gt; class to maximum width. The current version of Google AJAX Search creates the results in a html element with &lt;code&gt;width=300px&lt;/code&gt;. We want it to occupy the whole width of its container so we override Google's default setting&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Step 4: Applying Google's Magic&lt;/h3&gt;This step was assembled with the help of the Google AJAX Search API documentation, at &lt;a href="http://code.google.com/apis/ajaxsearch/documentation/"&gt;http://code.google.com/apis/ajaxsearch/documentation/&lt;/a&gt; &lt;br /&gt;
So we will add the next declaration to our page's  section: &lt;br /&gt;
&lt;pre id="pre2" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;pre id="pre3" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;link&lt;/span&gt; &lt;span class="code-attribute"&gt;href&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;http://www.google.com/uds/css/gsearch.css"&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text/css"&lt;/span&gt; &lt;span class="code-attribute"&gt;
&lt;/span&gt;      &lt;span class="code-attribute"&gt;rel&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;stylesheet"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text/javascript"&lt;/span&gt; &lt;span class="code-attribute"&gt;
&lt;/span&gt;   &lt;span class="code-attribute"&gt;src&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;http://www.google.com/uds/api?file=uds.js&amp;amp;v=1.0&amp;amp;key=YOUR_KEY"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre3" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;Please note that "YOUR_KEY" should be replaced by a key that you can get at &lt;a href="http://code.google.com/apis/ajaxsearch/signup.html"&gt;http://code.google.com/apis/ajaxsearch/signup.html&lt;/a&gt; &lt;br /&gt;
Now we'd add the next javascript code to the  section:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre4" lang="javascript" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;var&lt;/span&gt; searchControl window.onload = &lt;span class="code-keyword"&gt;function&lt;/span&gt;() {
    onLoad();
}
&lt;span class="code-keyword"&gt;function&lt;/span&gt; onLoad() {
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; Create a search control
&lt;/span&gt;
    searchControl = &lt;span class="code-keyword"&gt;new&lt;/span&gt; GSearchControl();

    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; add a regular web search, with a custom label 'web'
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;var&lt;/span&gt; webSrearch = &lt;span class="code-keyword"&gt;new&lt;/span&gt; GwebSearch();
    webSrearch.setUserDefinedLabel(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;web"&lt;/span&gt;);
    searchControl.addSearcher(webSrearch);

    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; add a site-limited web search, with a custom label
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;var&lt;/span&gt; siteSearch = &lt;span class="code-keyword"&gt;new&lt;/span&gt; GwebSearch();
    siteSearch.setUserDefinedLabel(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;KenEgozi.com"&lt;/span&gt;);
    siteSearch.setSiteRestriction(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;kenegozi.com"&lt;/span&gt;);
    searchControl.addSearcher(siteSearch);
                
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; add a blog search, with a custom label
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;var&lt;/span&gt; blogsSrearch = &lt;span class="code-keyword"&gt;new&lt;/span&gt; GblogSearch();
    blogsSrearch.setUserDefinedLabel(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;weblogs"&lt;/span&gt;);
    searchControl.addSearcher(blogsSrearch);

    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; setting the draw mode for the Google search
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;var&lt;/span&gt; drawOptions = &lt;span class="code-keyword"&gt;new&lt;/span&gt; GdrawOptions();
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; use tabbed view
&lt;/span&gt;
    drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; set the input field (instead of the default one)
&lt;/span&gt;
    drawOptions.setInput(document.getElementById(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;query'&lt;/span&gt;));
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; actually write the needed markup to the page
&lt;/span&gt;
    searchControl.draw(document.getElementById(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;searchcontrol"&lt;/span&gt;), drawOptions);
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; set the google logo container
&lt;/span&gt;
    GSearch.getBranding(document.getElementById(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;branding"&lt;/span&gt;));
}&amp;nbsp;&lt;/pre&gt;&lt;pre id="pre4" lang="javascript" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;And we're almost done&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Step 5: Adding a little DHTML Mojo&lt;/h3&gt;Now we'll add the ability to type anywhere on the page and get the  search field updated. We'll achieve that by adding this simple  javascript to the previous block: &lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre5" lang="javascript" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;var&lt;/span&gt; query = &lt;span class="code-keyword"&gt;null&lt;/span&gt;;
document.onkeydown = &lt;span class="code-keyword"&gt;function&lt;/span&gt;(event) { kd(event); };
&lt;span class="code-keyword"&gt;function&lt;/span&gt; kd(e) {
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; make it work on FF and IE
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;if&lt;/span&gt; (!e) e = event;
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; use ESC to clear the search results
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;if&lt;/span&gt; (e.keyCode == &lt;span class="code-digit"&gt;27&lt;/span&gt;)
        searchControl.clearAllResults();
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get the input field
&lt;/span&gt;
    &lt;span class="code-keyword"&gt;if&lt;/span&gt; (query == &lt;span class="code-keyword"&gt;null&lt;/span&gt;)
        query = document.getElementById(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;query'&lt;/span&gt;);
    &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; and move the focus in there
&lt;/span&gt;
    query.focus();
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-8859746966976193846?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/nKhAV3ti878" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/8859746966976193846/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/coolnsimple-search-page-using-google.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8859746966976193846?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/8859746966976193846?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/nKhAV3ti878/coolnsimple-search-page-using-google.html" title="A cool'n'simple search page using Google AJAX Search API, and some DHTML" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/coolnsimple-search-page-using-google.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQCRHo4fip7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-6162711129824715646</id><published>2010-09-27T03:45:00.000-07:00</published><updated>2010-09-27T03:46:05.436-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T03:46:05.436-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Salajax: simple Ajax library solving back button and bookmarks for Ajax web applications</title><content type="html">Salajax is a simplified Ajax library that handles back buttons,  bookmarks and is extremely simple to use. Yes, Ajax is great. It does  have some minor issues though, like the back button not working and the  inability to use bookmarks. This library provides a simple class that  will handle all these issues and more, without you having to think about  it too much.&lt;br /&gt;
The Simple Ajax Library Ajax class (Salajax) tries to: &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Make the back button work with Ajax &lt;/li&gt;
&lt;li&gt;Make bookmarks work with Ajax &lt;/li&gt;
&lt;li&gt;Run JavaScript contained in the Ajax response &lt;/li&gt;
&lt;li&gt;Keep the .NET Viewstate &lt;/li&gt;
&lt;li&gt;Submit forms as an Ajax request &lt;/li&gt;
&lt;li&gt;Specify &lt;code&gt;OnStart&lt;/code&gt; and &lt;code&gt;OnEnd&lt;/code&gt; JavaScript functions to call &lt;/li&gt;
&lt;li&gt;Specify an &lt;code&gt;OnError&lt;/code&gt; JavaScript function to call when the Ajax response is an error &lt;/li&gt;
&lt;li&gt;Set the HTML to display when updating a div with an Ajax request &lt;/li&gt;
&lt;li&gt;Set the HTML to display when there is an error making the Ajax request &lt;/li&gt;
&lt;li&gt;Be extremely simple to use &lt;/li&gt;
&lt;/ul&gt;Basically, I'm hoping that the Salajax class will make it very easy  to do everything and anything you could possibly want to do using Ajax.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h2&gt;Background&lt;/h2&gt;This article presents a simplified Ajax library written in  JavaScript. Hopefully many developers will find it useful. Ajax is an  exciting new technology that will change the way we develop our web  applications. That was the introduction to the fist article I wrote on  Ajax, presenting a simplified Ajax library with only two methods. I  called it SAL, for Simplified Ajax Library.&lt;br /&gt;
&lt;br /&gt;
Yes, Ajax was the big buzzword. It was going to revolutionise the web  and the way we developed applications. Then somebody noticed a few  minor problems, i.e. the back button did not work properly; users would  most likely end up at the previous site they were visiting or become  confused. Also, developers found that they couldn't run the JavaScript  that was returned in the Ajax responses, plus more problems.&lt;br /&gt;
&lt;br /&gt;
That's why I decided to build the next simplified Ajax library or SAL  version 2. Things I wanted to add at the beginning were: making it a  self-contained class, making the back button work, accounting for  Viewstate, and giving backwards compatibility with SAL v1. Things I  added on the way were: OnEvents, having customisable HTML when updating  or at an error, and getting bookmarks to work. Also, updating multiple  sections seems to be run on different threads now.&lt;br /&gt;
&lt;br /&gt;
Not all the code is mine. I found some code on the internet that fits  well and have maybe edited it. One example of this is the hash listener  class, for which I have left the original comments of the author.  However, a lot of the code is written by me. I can't guarantee that this  will work on all browsers, however. It really does use a lot of complex  JavaScript to make the back buttons work, etc. I have tested it in  FireFox 2.0.0.3 and IE 6.0.2900.2180; it works well with those. &lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Using the code&lt;/h2&gt;Well, initially you will have to include the JS file in the head of your page like this:&lt;br /&gt;
&lt;pre id="pre0" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt; &lt;span class="code-attribute"&gt;language&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;JavaScript"&lt;/span&gt; &lt;span class="code-attribute"&gt;src&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Salajax.js"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;Here is the comment contained at the top of the Salajax.js class:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="jscript" style="margin-top: 0pt;"&gt;&lt;span class="code-comment"&gt;/*&lt;/span&gt;&lt;span class="code-comment"&gt;
The Salajax Class.
Ajax class that allows use of the back button and bookmarks.
Written by Nigel Liefrink.

Usage:
    //set up the Salajax settings. Do this in the  of the page
    var SAL = new Salajax();
    sal.Debug = 0;
    sal.EnableBackButton(true); //turns on the back buttons.
    sal.EnableBookmarks(true); 
        //saves state in the clients cookies so bookmarks will work
        //provided they havn't deleted their cookies.
    sal.OnStart = 'TestOnStart()'; //enables a script to run before 
        //the request is made. e.g. change pointer/icon/loading section of 
        //page.
    sal.OnEnd = 'TestOnEnd()'; 
        //enables a script to run after the request is returned. 
        //e.g. change pointer/icon/loading section of page.
    sal.PresendHtml = '&lt;img border="0" src="loading24-1.gif" /&gt;';
        //When calling  setInnerHTMLFromAjaxResponse the div will 
        //be updated with this html, set to null to turn off this feature.
    sal.OnError = 'DefaultOnError()';
        //set a function to pass to if there is an error.
    sal.OnErrorHtml = 
        '&lt;img border="0" src="error_icon.gif" /&gt;&lt;span style="color: red;"&gt;Error!&lt;/span&gt;'; 
        //When calling  setInnerHTMLFromAjaxResponse and there is 
        //an error, this will be displayed. set to null to turn off 
        //this feature.
    sal.EvalScripts = true;  
        //if set to true, will evaluate any JavaScript in the responseText. 
        //NOTE: to use/override functions returned in your responseText you 
        //must declare the functions in your Ajax response like this:
        //         var FunctionToChange = function(var1,var2) 
        //not like this : function FunctionToChange(var1,var2)
        //         { 
        //             //do stuff
        //         }
        //            
    this.KeepDotNetViewState = true; 
    //if set to true will post the current viewstate when using .NET 
    //not recommended when using bookmarks as viewstate can be huge.
    //end setting the Salajax settings.
    
    
    Some examples of main usage in a web page: (onclick events etc...)
    
    sal.PassAjaxResponseToFunction('/myscript.*?getsomehtml=1', 
        'FunctionToHandleTheResponse');
    sal.PassAjaxResponseToFunction(document.forms[0], 
        'FunctionToHandleTheResponse');

    sal.SetInnerHTMLFromAjaxResponse('/myscript.*?getsomehtml=1', 
        'id_of_div'); //using get and string of id div.
    sal.SetInnerHTMLFromAjaxResponse(document.forms[0], 
        object);//using post and object to change the innerhtml of.
    sal.SetInnerHTMLFromAjaxResponse('form', 
        'id_of_div');//using post ('form' will submit forms[0]'), 
                     //object to change the innerhtml of.

    Read function definitions for more detail.
    Note that initial values are all false for backward compatability.
*/&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
If you want back buttons to work for some calls but not others, simply create another instance of the class. &lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre2" lang="jscript" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;var&lt;/span&gt; SAL = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Salajax();
sal.EnableBackButtons(&lt;span class="code-keyword"&gt;true&lt;/span&gt;)
&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;in the web page
&lt;/span&gt;
&amp;lt;input class="code-string" type="&amp;lt;span" "&lt;span class="code-string"&gt;submit"&lt;/span&gt; value=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;OK"&lt;/span&gt; 
    onclick=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;sal.SetInnerHtmlFromAjaxResponse('form','div_1');"&lt;/span&gt; /&amp;gt;

&lt;span class="code-keyword"&gt;var&lt;/span&gt; sal2 = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Salajax();
&lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt;in the web page
&lt;/span&gt;
&amp;lt;input class="code-string" type="&amp;lt;span" "&lt;span class="code-string"&gt;submit"&lt;/span&gt; value=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;OK"&lt;/span&gt; 
    onclick=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;sal2.SetInnerHtmlFromAjaxResponse('?gethtml=1','div_2');"&lt;/span&gt; /&amp;gt;&lt;/pre&gt;&lt;pre id="pre2" lang="jscript" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre id="pre2" lang="jscript" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;
For backwards compatibility with SAL version 1, I have included these two functions at the top of the script. THey demonstrate how you can use many instances to handle Ajax requests differently.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre3" lang="jscript" style="margin-top: 0pt;"&gt;&lt;span class="code-comment"&gt;/*&lt;/span&gt;&lt;span class="code-comment"&gt; Backward compatability. */&lt;/span&gt;
&lt;span class="code-keyword"&gt;function&lt;/span&gt; PassAjaxResponseToFunction(urlOrForm, callbackFunction)
{
    &lt;span class="code-keyword"&gt;var&lt;/span&gt; SAL = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Salajax();
    sal.PresendHtml = &lt;span class="code-keyword"&gt;null&lt;/span&gt;;
    sal.OnError = &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;'&lt;/span&gt;;
    sal.ErrorHtml == &lt;span class="code-keyword"&gt;null&lt;/span&gt;;
    sal.PassAjaxResponseToFunction(urlOrForm, callbackFunction);
}

&lt;span class="code-comment"&gt;/*&lt;/span&gt;&lt;span class="code-comment"&gt; Backward compatability. */&lt;/span&gt;
&lt;span class="code-keyword"&gt;function&lt;/span&gt; SetInnerHTMLFromAjaxResponse(urlOrForm, obj_id)
{
    &lt;span class="code-keyword"&gt;var&lt;/span&gt; SAL = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Salajax();
    sal.PresendHtml = &lt;span class="code-keyword"&gt;null&lt;/span&gt;;
    sal.OnError = &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;'&lt;/span&gt;;
    sal.ErrorHtml == &lt;span class="code-keyword"&gt;null&lt;/span&gt;;
    sal.SetInnerHTMLFromAjaxResponse(urlOrForm, obj_id);
}&lt;/pre&gt;&lt;pre id="pre3" lang="jscript" style="margin-top: 0pt;"&gt;&amp;nbsp;&lt;/pre&gt;There's not much more to it than that. Just create the instance, set  the properties and then start using the 2 main functions of the Salajax  class in JavaScript events. To get the demo project working, unzip the &lt;i&gt;Salajax_demo.zip&lt;/i&gt;  file to an appropriate location like wwwroot, but anywhere will do.  Create a virtual directory in Information Services Manager/IIS under the  "Default Web Site" with an alias of "sal_demo" and the directory path  referencing the sal_demo folder you unzipped. Opening the project in  Visual Studio, you should now be able to compile, debug and run the demo  project.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Points of interest&lt;/h2&gt;Cookies can only hold 4 Kb of data. So if you are keeping a lot of  data in your forms, such as the .NET Viewstate, keeping bookmarks and  the back button working with Ajax may not be the ideal solution for you.&lt;br /&gt;
Threading for each of the JavaScript calls now seems to work  differently -- multiple threads -- now that the calls are wrapped up in  an instance class. &lt;br /&gt;
The complexity of the JavaScript used to make the back button work  makes me think that this code will most likely not be compatible with  some browsers. It would be good to get feedback on compatibility from  people.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-6162711129824715646?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/lKQwLGkgBlw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/6162711129824715646/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/salajax-simple-ajax-library-solving.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6162711129824715646?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6162711129824715646?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/lKQwLGkgBlw/salajax-simple-ajax-library-solving.html" title="Salajax: simple Ajax library solving back button and bookmarks for Ajax web applications" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/salajax-simple-ajax-library-solving.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEIFQ385fSp7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-5638977261135872688</id><published>2010-09-27T03:15:00.000-07:00</published><updated>2010-09-27T03:15:12.125-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T03:15:12.125-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Dragging and dropping with ASP.NET 2.0 and Atlas</title><content type="html">&lt;img src="http://www.codeproject.com/KB/ajax/AtlasDragNDrop/AtlasDragNDrop.gif" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This tutorial is intended to help readers understand how certain aspects of Microsoft's new AJAX Extensions technology works. AJAX Extensions is intended to simplify the development of AJAX-style functionality. As with all technologies, however, to use a tool well, it is important to understand the underlying technology that Atlas abstracts. One of the key ASP.NET AJAX abstractions is the new XML markup syntax developed to make coding with AJAX easier (originally included with the core Atlas files, XML markup is now a part of the CTP called AJAX Futures). With XML markup, developers can modify their code declaratively. However, there are times when a developer may want to be able to change her code programmatically, and in order to accomplish this, she will need to understand that underneath the markup abstraction, she is actually dealing with good 'ol JavaScript and some custom JavaScript libraries developed by Microsoft. In order to demonstrate the relationship between the Atlas declarative model and the programmatic model, I will go through a series of examples in which the same task will be accomplished both declaratively and programmatically. I will be demonstrating how to use the PreviewDragDrop library file to perform basic drag-drop operations as well as setting up drop zones.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Background&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As I write this, Microsoft has made some important changes to ASP.NET AJAX for the Beta 2 that have the unfortunate side-effect of breaking most of the original Atlas implementation, and has required a bit of rework of the original samples. These revised examples apply to the Beta 2 of ASP.NET AJAX. Future releases of AJAX Extensions may affect the accuracy of this tutorial. I will attempt to update the code as new versions of AJAX Extensions become available. AJAX Extensions works with .NET 2.0, and will work with Orcas when it is released.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;I. Declarative Drag Drop&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The first task is to use XML markup to add drag-drop behavior to a div tag. By drag and drop, I just mean the ability to drag an object and then have it stay wherever you place it. The more complicated behavior of making an object actually do something when it is dropped on a specified drop target will be addressed later in this tutorial. To configure your webpage to use ASP.NET AJAX, you will need to install the Microsoft.Web.Extensions.dll into your Global Assembly Cache. You will also need a reference to the library Microsoft.Web.Preview.dll. Finally, you will need to configure your web.config file with the following entry:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre0" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;system.web&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;pages&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;controls&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;add&lt;/span&gt; &lt;span class="code-attribute"&gt;tagPrefix&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;asp"&lt;/span&gt; &lt;span class="code-attribute"&gt;namespace&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.UI"&lt;/span&gt; 
                 &lt;span class="code-attribute"&gt;assembly&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Extensions, Version=1.0.61025.0, 
                 Culture=neutral,  PublicKeyToken=31bf3856ad364e35"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;add&lt;/span&gt; &lt;span class="code-attribute"&gt;tagPrefix&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;asp"&lt;/span&gt; &lt;span class="code-attribute"&gt;namespace&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.UI.Controls"&lt;/span&gt; 
                 &lt;span class="code-attribute"&gt;assembly&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Extensions, Version=1.0.61025.0, 
                 Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;add&lt;/span&gt; &lt;span class="code-attribute"&gt;tagPrefix&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;asp"&lt;/span&gt; &lt;span class="code-attribute"&gt;namespace&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Preview.UI"&lt;/span&gt; 
                 &lt;span class="code-attribute"&gt;assembly&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Preview"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;controls&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;pages&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;system.web&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
You will need to add an Atlas Script Manager control to your .aspx page and configure it to use the PreviewDragDrop library file:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptManager&lt;/span&gt; &lt;span class="code-attribute"&gt;ID&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;ScriptManager1"&lt;/span&gt; &lt;span class="code-attribute"&gt;runat&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;server"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;Scripts&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptReference&lt;/span&gt; 
             &lt;span class="code-attribute"&gt;Name&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptReference&lt;/span&gt; 
      &lt;span class="code-attribute"&gt;Name&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Resources.ScriptLibrary.PreviewDragDrop.js"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;Scripts&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptManager&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
Add the &lt;code lang="html"&gt;div&lt;/code&gt; object you want to make draggable, and make sure it has a drag handle:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;style&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;background-color:Red;height:800px;width:600px;"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;draggableDiv"&lt;/span&gt; 
         &lt;span class="code-attribute"&gt;style&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;height:100px;width:100px;background-color:Blue;"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;handleBar"&lt;/span&gt; 
             &lt;span class="code-attribute"&gt;style&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;height:20px;width:auto;background-color:Green;"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
Finally, add the markup script that will make your &lt;code lang="html"&gt;div&lt;/code&gt; draggable:&lt;br /&gt;
&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text/xml-script"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;page class="code-string" xmlns:script="&amp;lt;span"&gt;"&lt;span class="code-string"&gt;http://schemas.microsoft.com/xml-script/2005"&lt;/span&gt;&amp;gt;
        &lt;components&gt;
            &lt;control class="code-string" id="&amp;lt;span"&gt;"&lt;span class="code-string"&gt;draggableDiv"&lt;/span&gt;&amp;gt;
                &lt;behaviors&gt;
                    &lt;floatingbehavior class="code-string" handle="&amp;lt;span"&gt;"&lt;span class="code-string"&gt;handleBar"&lt;/span&gt;/&amp;gt;
                &lt;span class="code-keyword"&gt;&lt;span class="code-leadattribute"&gt;behaviors&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;control&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;components&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;page&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/floatingbehavior&gt;&lt;/behaviors&gt;&lt;/control&gt;&lt;/components&gt;&lt;/page&gt;&lt;/pre&gt;&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
And with that, you should have a draggable &lt;code lang="html"&gt;div&lt;/code&gt; &lt;br /&gt;
tag. The example demonstrates the simplicity and ease of using the &lt;br /&gt;
declarative model with AJAX Extensions. In the terminology being &lt;br /&gt;
introduced with AJAX Futures, you have just used declarative markup to &lt;br /&gt;
add floating behavior to an HTML element.&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="xml" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;h2&gt;II. Imperative Drag Drop&lt;/h2&gt;To accomplish the same thing using a programmatic model requires a  bit more code, but not much more. It is important to understand that  when you add an AJAX Extensions Script Manager component to your page,  you are actually giving instructions to have the AJAX Extensions  JavaScript library loaded into your page. The AJAX Extensions library,  among other things, provides client-side classes that extend the DOM and  provide you with tools that allow you to code in a browser agnostic  manner (though there currently are still issues with Safari  compatibility). These client-side classes also allow you to add  behaviors to your HTML elements. &lt;br /&gt;
To switch to an imperative model, you will need to replace the XML  markup with two JavaScript functions. The first one is a generic script  to add floating behavior to an HTML element. It leverages the AJAX  Extensions client-side classes to accomplish this:&lt;br /&gt;
&lt;pre id="pre4" lang="jscript" style="margin-top: 0pt;"&gt;&lt;script class="code-string" type="&amp;lt;span"&gt;
"&lt;/span&gt;&lt;span class="code-string"&gt;text/javascript"&lt;/span&gt;&gt;
    &lt;span class="code-keyword"&gt;function&lt;/span&gt; addFloatingBehavior(ctrl, ctrlHandle){  
            $create(Sys.Preview.UI.FloatingBehavior, 
                  {&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;handle'&lt;/span&gt;: ctrlHandle},&lt;span class="code-keyword"&gt;null&lt;/span&gt;, &lt;span class="code-keyword"&gt;null&lt;/span&gt;, ctrl);
         }
&lt;span class="code-keyword"&gt;&lt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin-top: 0pt;" id="pre4" lang="jscript"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;

The function takes two parameter values: the HTML element that you 
want to make draggable, and the HTML element that is the drag handle for
 the dragging behavior.&amp;nbsp;The new &lt;code&gt;$create&lt;/code&gt; function encapsulates the instantiation and initialization routines for the behavior. The &lt;code&gt;addFloatingBehavior&lt;/code&gt; utility function will be used throughout the rest of this tutorial.&amp;nbsp;&lt;/p&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;p&gt;

Now, you need to call the "&lt;code&gt;addFloatingBehavior(...)&lt;/code&gt;" 
function when the page loads. This, surprisingly, was the hardest part 
about coding this example. The Script Manager doesn't simply create a 
reference to the AJAX Extensions JavaScript libraries, and I have read 
speculation that it actually loads the library scripts into the DOM. In 
any case, what this means is that the libraries get loaded only after 
everything else on the page is loaded. The problem for us, then, is that
 there is no standard way to make our code that adds the floating 
behavior run after the libraries are loaded; and if we try to run it 
before the libraries are loaded, we simply generate JavaScript errors, 
since all of the AJAX Extensions methods we call can't be found. &lt;/p&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;p&gt;

There are actually a few workarounds for this, but the easiest one is to use a custom AJAX Extensions event called "&lt;code&gt;pageLoad()&lt;/code&gt;" that&amp;nbsp; only gets called after the libraries are loaded. To add the floating behavior to your &lt;code lang="html"&gt;div&lt;/code&gt; tag when the page is first loaded (but after the library scripts are loaded), you just need to write the following: &lt;/p&gt;&lt;pre style="margin-top: 0pt;" id="pre4" lang="jscript"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;pre style="margin-top: 0pt;" id="pre5" lang="jscript"&gt;&lt;script type=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;text/javascript"&lt;/span&gt;&gt;
    &lt;span class="code-keyword"&gt;function&lt;/span&gt; pageLoad(){
        addFloatingBehavior(document.getElementById(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;draggableDiv'&lt;/span&gt;),
                            document.getElementById(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;handleBar'&lt;/span&gt;));
    }
&lt;span class="code-keyword"&gt;&lt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin-top: 0pt;" id="pre1" lang="xml"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="code-keyword"&gt; &lt;/span&gt;&lt;/pre&gt;&lt;p&gt;

&amp;nbsp;which, in turn, can be written this way, using an AJAX Extensions script shorthand that replaces "&lt;code&gt;document.getElementById()&lt;/code&gt;" with "&lt;code&gt;$get()&lt;/code&gt;":&lt;/p&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;pre style="margin-top: 0pt;" id="pre6" lang="jscript"&gt;&lt;script type=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;text/javascript"&lt;/span&gt;&gt;
    &lt;span class="code-keyword"&gt;function&lt;/span&gt; pageLoad(){
        addFloatingBehavior($get(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;draggableDiv'&lt;/span&gt;),$get(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;handleBar'&lt;/span&gt;));
    }
&lt;span class="code-keyword"&gt;&lt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin-top: 0pt;" id="pre6" lang="jscript"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;

And once again, you have a draggable &lt;code lang="html"&gt;div&lt;/code&gt; that behaves exactly the same as the draggable &lt;code lang="html"&gt;div&lt;/code&gt; you wrote using the declarative model.&lt;/p&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;h2&gt;





III. Dynamic Drag Drop&lt;/h2&gt;&lt;p&gt;

Since the declarative model is much cleaner than the imperative 
model, why would you ever want to write your own JavaScript to handle 
AJAX Extensions behaviors? You might want to roll your own JavaScript if
 you want to add behaviors dynamically. One limitation of the 
declarative model is that you can only work with objects that are 
initially on the page. If you start adding objects to the page 
dynamically, you cannot add the floating behavior to them using the 
declarative model. With the imperative model, on the other hand, you 
can.&lt;/p&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;p&gt;

Building on the previous example, you will replace the "&lt;code&gt;pageLoad()&lt;/code&gt;" function with a function that creates floating &lt;code lang="html"&gt;div&lt;/code&gt;s on demand. The following JavaScript function will create a &lt;code lang="html"&gt;div&lt;/code&gt; tag with another &lt;code lang="html"&gt;div&lt;/code&gt; tag embedded to use as a handlebar, then insert the &lt;code lang="html"&gt;div&lt;/code&gt; tag into the current page, and finally add floating behavior to the &lt;code lang="html"&gt;div&lt;/code&gt; tag:&lt;/p&gt;&lt;p&gt;

&amp;nbsp;&lt;/p&gt;&lt;/script&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;pre&gt;function createDraggableDiv() {
    var panel= document.createElement("div");
    panel.style.height="100px";
    panel.style.width="100px";
    panel.style.backgroundColor="Blue";
    var panelHandle = document.createElement("div");
    panelHandle.style.height="20px";
    panelHandle.style.width="auto";
    panelHandle.style.backgroundColor="Green";
    panel.appendChild(panelHandle);
    var target = $get('containerDiv').appendChild(panel);
    addFloatingBehavior(panel, panelHandle);
}
&lt;/pre&gt;&lt;br /&gt;
You will then just need to add a button to the page that calls the "&lt;code&gt;createDraggableDiv()&lt;/code&gt;" function. The new HTML body should look something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre8" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;input&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;button"&lt;/span&gt; &lt;span class="code-attribute"&gt;value&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Add Floating Div"&lt;/span&gt; &lt;span class="code-attribute"&gt;onclick&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;createDraggableDiv();"&lt;/span&gt; &lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;containerDiv"&lt;/span&gt; &lt;span class="code-attribute"&gt;style&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;background-color:Purple;height:800px;width:600px;"&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre8" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
This will allow you to add as many draggable elements to your page as &lt;br /&gt;
you like, thus demonstrating the power and flexibility available to you &lt;br /&gt;
once you understand the relationship between using AJAX Extensions &lt;br /&gt;
declaratively and using it programmatically. As a point of reference, &lt;br /&gt;
here is the complete code for the dynamic drag and drop example:&lt;br /&gt;
&lt;pre id="pre8" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-keyword"&gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre id="pre8" lang="html" style="margin-top: 0pt;"&gt;&lt;span class="code-pagedirective"&gt;&amp;lt;%@&lt;/span&gt;&lt;span class="code-leadattribute"&gt; Page Language&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;C#"&lt;/span&gt;&lt;span class="code-attribute"&gt;  &lt;/span&gt;&lt;span class="code-pagedirective"&gt;%&amp;gt;&lt;/span&gt;

&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;!DOCTYPE&lt;/span&gt; &lt;span class="code-attribute"&gt;html&lt;/span&gt; &lt;span class="code-attribute"&gt;PUBLIC&lt;/span&gt; &lt;span class="code-attribute"&gt;"-&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;W3C&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;DTD&lt;/span&gt; &lt;span class="code-attribute"&gt;XHTML&lt;/span&gt; &lt;span class="code-attribute"&gt;1.0&lt;/span&gt; &lt;span class="code-attribute"&gt;Transitional&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;EN"&lt;/span&gt; 
     &lt;span class="code-attribute"&gt;"http:&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;www.w3.org&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;TR&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;xhtml1&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;DTD&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-attribute"&gt;xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;html&lt;/span&gt; &lt;span class="code-attribute"&gt;xmlns&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;head&lt;/span&gt; &lt;span class="code-attribute"&gt;runat&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;server"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;title&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;Imperative Drag and Drop II&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;title&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;text/javascript"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        
        function createDraggableDiv() {
             var panel = document.createElement(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;div"&lt;/span&gt;);
             panel.style.height=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;100px"&lt;/span&gt;;
             panel.style.width=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;100px"&lt;/span&gt;;
             panel.style.backgroundColor=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Blue"&lt;/span&gt;;
             var panelHandle = document.createElement(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;div"&lt;/span&gt;);
             panelHandle.style.height=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;20px"&lt;/span&gt;;
             panelHandle.style.width=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;auto"&lt;/span&gt;;
             panelHandle.style.backgroundColor=&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Green"&lt;/span&gt;;
             panel.appendChild(panelHandle);
             var target = $get(&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;containerDiv'&lt;/span&gt;).appendChild(panel);
             addFloatingBehavior(panel, panelHandle);
             }
            
            function addFloatingBehavior(ctrl, ctrlHandle){
                 $create(Sys.Preview.UI.FloatingBehavior,
                {&lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;handle'&lt;/span&gt;:
                    ctrlHandle}, &lt;span class="code-keyword"&gt;null&lt;/span&gt;, 
                        &lt;span class="code-keyword"&gt;null&lt;/span&gt;, ctrl);
                     }

&lt;span class="code-keyword"&gt;&lt;span class="code-leadattribute"&gt;script&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;head&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;body&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;form&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;form1"&lt;/span&gt; &lt;span class="code-attribute"&gt;runat&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;server"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptManager&lt;/span&gt; &lt;span class="code-attribute"&gt;ID&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;ScriptManager1"&lt;/span&gt; &lt;span class="code-attribute"&gt;runat&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;server"&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;Scripts&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptReference&lt;/span&gt; 
           &lt;span class="code-attribute"&gt;Name&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js"&lt;/span&gt;
&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptReference&lt;/span&gt; 
   &lt;span class="code-attribute"&gt;Name&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Microsoft.Web.Resources.ScriptLibrary.PreviewDragDrop.js"&lt;/span&gt;
&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;Scripts&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;asp:ScriptManager&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;h2&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;Imperative Drag and Drop Code with javascript: 
         demonstrate dynamic loading of behaviors&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;h2&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;input&lt;/span&gt; &lt;span class="code-attribute"&gt;type&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;button"&lt;/span&gt; &lt;span class="code-attribute"&gt;value&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;Add Floating Div"&lt;/span&gt; 
          &lt;span class="code-attribute"&gt;onclick&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;createDraggableDiv();"&lt;/span&gt;
&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-leadattribute"&gt;div&lt;/span&gt; &lt;span class="code-attribute"&gt;id&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;containerDiv"&lt;/span&gt; 
   &lt;span class="code-attribute"&gt;style&lt;/span&gt;&lt;span class="code-keyword"&gt;="&lt;/span&gt;&lt;span class="code-keyword"&gt;background-color:Purple;height:800px;width:600px;"&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;form&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;body&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="code-keyword"&gt;&amp;lt;&lt;/span&gt;&lt;span class="code-keyword"&gt;/&lt;/span&gt;&lt;span class="code-leadattribute"&gt;html&lt;/span&gt;&lt;span class="code-keyword"&gt;&amp;gt;&lt;/span&gt;&lt;span class="code-keyword"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-5638977261135872688?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/L_0uegt-v_o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/5638977261135872688/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/dragging-and-dropping-with-aspnet-20.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/5638977261135872688?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/5638977261135872688?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/L_0uegt-v_o/dragging-and-dropping-with-aspnet-20.html" title="Dragging and dropping with ASP.NET 2.0 and Atlas" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/dragging-and-dropping-with-aspnet-20.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QFSXYzeyp7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-4638048871323537112</id><published>2010-09-27T02:55:00.000-07:00</published><updated>2010-09-27T02:55:18.883-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T02:55:18.883-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Ajax AutoComplete in ASP.NET</title><content type="html">Without using AjaxControlToolKit, we can implement AutoComplete  Extender using pure Ajax Call. This article explains how to do make  AutoComplete Extender.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;OnKeyUp &lt;/code&gt;event helps you to fetch data from database with Ajax call. Here one &lt;i&gt;Handler.ashx&lt;/i&gt;  handles the AJAX request form Client. I add a Class file to handle  database operations to better coding practice. Below I explain the  database helper &lt;code&gt;Class&lt;/code&gt;. &lt;code&gt;Class &lt;/code&gt;has one method:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;GetTable(string sqlQuery) &lt;/pre&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
This returns &lt;code&gt;DataTable &lt;/code&gt;after fetching data from database. And also includes &lt;code&gt;Provide &lt;/code&gt;Class, this Class helps to get &lt;code&gt;SqlConnection &lt;/code&gt;string.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
/// &lt;summary&gt;
/// Summary description for DBHelper
/// &lt;/summary&gt;
public class DBHelper
{
    SqlConnection connection;
    SqlDataAdapter adapter;
    SqlCommand command;
    DataTable dataTable;
    public DBHelper()
    {
    }
    /// &lt;summary&gt;
    /// 
    /// &lt;/summary&gt;
    /// 



&lt;param name="sqlQuery" /&gt;passing SQL Query here
    /// &lt;returns&gt;DataTable object is returned&lt;/returns&gt;
    public DataTable GetTable(string sqlQuery)
    {
        //creating new instance of Datatable
        dataTable = new DataTable();
        connection = Provider.GetConnection();
        command = new SqlCommand(sqlQuery, connection);
        //Open SQL Connection
        connection.Open();
            try
            {
                adapter = new SqlDataAdapter(command);
                adapter.Fill(dataTable);
            }
            catch
            { }
            finally
            {
                //Closing Sql Connection 
                connection.Close();
            }
        return dataTable;
    }
}
public class Provider
{
    public static SqlConnection GetConnection()
    {
        //creating SqlConnection
        return new SqlConnection(ConfigurationManager.AppSettings["sqlConn"]);
    }
} &lt;/pre&gt;&lt;br /&gt;
Now we can look into Handler file. When request comes from Ajax Call  from Client, it passes the data into our Database helper Class, handler  file holds the data in &lt;code&gt;DataTable&lt;/code&gt;. Result data are formatted in a table and written in the context. We can add JavaScript function for selecting the data, here &lt;code&gt;api_helper.AddtoTaxtBox(selectedItem)&lt;/code&gt;&lt;b&gt; &lt;/b&gt;manages client section of data.&lt;br /&gt;
&lt;h4&gt;Check Handler File&lt;/h4&gt;&lt;pre&gt;&amp;lt;%@ WebHandler Language="C#" Class="Handler" %&amp;gt;
using System;
using System.Web;
using System.Data;
public class Handler : IHttpHandler {
    public void ProcessRequest (HttpContext context) {

        HttpRequest request = HttpContext.Current.Request;
        //checking string null or empty
        if (!string.IsNullOrEmpty(request.QueryString["name"]))
        {
            string name=request.QueryString["name"];
            //creating instance of new database helper
            DBHelper objDBHelper = new DBHelper();
            //creating Sql Query
            string sqlQuery = string.Format
        ("SELECT Name FROM User WHERE Name LIKE '{0}%'", name);
            //filling data from database
            DataTable dataTable = objDBHelper.GetTable(sqlQuery);

             string table = string.Empty;
            //table for hold data
            table = "

&lt;table&gt;";             string td = string.Empty;             //checking datatable                 if (dataTable.Rows.Count &amp;gt; 0)                 {                     for (int i = 0; i &amp;lt; dataTable.Rows.Count; i++)                     {                         //adding table rows                         td += string.Format("&lt;tbody&gt;
&lt;tr&gt;&lt;td class="select" onclick="api_helper.AddtoTaxtBox(this.innerHTML)"&gt;&lt;br /&gt;
{0}&lt;/td&gt;&lt;/tr&gt;
", dataTable.Rows[i][0].ToString());                     }                 }                 table += td + "&lt;/tbody&gt;&lt;/table&gt;";
                context.Response.Write(table);
        }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
}
&lt;/pre&gt;Now we can check how Ajax works. On &lt;code&gt;Textbox onKeyUp&lt;/code&gt; event, call the Ajax code. It sends the entered value into server using Ajax and the result is displayed in &lt;code&gt;div &lt;/code&gt;control under the search textbox.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" 

  CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;

  &amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;

  &amp;lt;head runat="server"&amp;gt;

  &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;

  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;

  &amp;lt;form id="form1" runat="server"&amp;gt;

  &amp;lt;div&amp;gt;
&amp;lt;asp:TextBox ID="txtName" runat="server" 

  onkeyup="api_helper.callAjax();"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;

  &amp;lt;div id="myDiv"&amp;gt;&amp;lt;/div&amp;gt;

  

  &amp;lt;/div&amp;gt;

  &amp;lt;script language="javascript" type="text/javascript"&amp;gt;
if (typeof (api_helper) == 'undefined') { api_helper = {} }
api_helper.doAjax = function(HandlerUrl, displayDiv) {

  var Req; try { Req = new XMLHttpRequest(); } 

  catch (e) { try { Req = new ActiveXObject("Msxml2.XMLHTTP"); }

  catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } 

  catch (e) { return false; } } } Req.onreadystatechange = function() {

  if (Req.readyState == 4) { var d = document.getElementById(displayDiv); 

  d.innerHTML = Req.responseText; } }

  Req.open("GET", HandlerUrl, true); Req.send(null);

  }
api_helper.callAjax = function() {

  var text = document.getElementById("txtName").value;

  if (text != "") {

  var requestUrl = "Handler.ashx?name=" + text;

  var displayDiv="myDiv";

  api_helper.doAjax(requestUrl, displayDiv);

  }

  }
api_helper.AddtoTaxtBox = function(txt) {

  document.getElementById("txtName").value = txt;

  document.getElementById("myDiv").innerHTML = "";

  }

  &amp;lt;/script&amp;gt; 

  &amp;lt;/form&amp;gt;

  &amp;lt;/body&amp;gt;

  &amp;lt;/html&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Thanks for reading this article. Please feel free to comment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-4638048871323537112?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/vgSaKwBm5dU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/4638048871323537112/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/ajax-autocomplete-in-aspnet.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/4638048871323537112?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/4638048871323537112?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/vgSaKwBm5dU/ajax-autocomplete-in-aspnet.html" title="Ajax AutoComplete in ASP.NET" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/ajax-autocomplete-in-aspnet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4FR344eCp7ImA9Wx5WFUU.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-887640790652174112</id><published>2010-09-27T02:48:00.000-07:00</published><updated>2010-09-27T02:48:36.030-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T02:48:36.030-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><title>Making Cross Domain jQuery AJAX Calls</title><content type="html">Today's web browsers do not allow web pages to make cross-domain Ajax  calls. By this, I mean that if you are at www.ajax.com and try to make  an Ajax call (a call using the &lt;code&gt;XmlHttpRequest &lt;/code&gt;object), the browser would not allow this to happen. Why? For security purposes that I cannot currently name.&lt;br /&gt;
&lt;br /&gt;
However, at some point you get to a project where you're interfacing  this third-party site that needs to talk to your main site, or some  other similar situation where the only way you're going to get the data  you need from point a to point b is with some JavaScript magic. Here is  how to accomplish it.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h4&gt;How to get/post data using jQuery/JavaScript (JSONP)&lt;/h4&gt;The short answer: its not Ajax at all, its JSONP. Yes, &lt;b&gt;JSONP is not Ajax&lt;/b&gt;.  I just learned this today. Like I said earlier, browsers do not allow  XHR/Ajax cross-browser requests. JSONP avoids this by making a request  for a script file-- no Ajax at all. Let me explain:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Instead of accessing the XHR object, the browser first creates a new script tag to inject into the HTML DOM&lt;/li&gt;
&lt;li&gt;The script tag's URL is set to the URL you're looking to get/post(using &lt;code&gt;HTTP GET&lt;/code&gt;) data to&lt;/li&gt;
&lt;li&gt;The script tag is injected into the page, causing...&lt;/li&gt;
&lt;li&gt;The request is sent to the server, even if it's cross-domain&lt;/li&gt;
&lt;li&gt;The server returns the data in the form of a JavaScript function call&lt;/li&gt;
&lt;li&gt;The browser receives the data and executes the function call&lt;/li&gt;
&lt;/ol&gt;&lt;h4&gt;jQuery Code&lt;/h4&gt;&lt;br /&gt;
&lt;pre&gt;//use a get to post a querystring value via HTTP GET to an asp.net webhandler
$.getJSON("http://www.example.com/get-post.ashx?
    var1=var1value&amp;amp;callback=?",function(data){
     //really no need to do anything here, we're just posting data
     //but this will output success
     alert(data.return);
});
&lt;/pre&gt;&lt;br /&gt;
&lt;h4&gt;ASP.NET Generic Handler/webhandler Code&lt;/h4&gt;&lt;pre&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace jsonp_test
{
    /// &lt;summary&gt;
    /// Summary description for $codebehindclassname$
    /// &lt;/summary&gt;
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class get_post : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string callback = "";
            try
            {
                if (!string.IsNullOrEmpty(context.Request["callback"]))
                {
                    if (!string.IsNullOrEmpty(context.Request["var1"]))
                        SaveData(context.Request["var1"]);
                    callback = context.Request["callback"];

                    context.Response.Write(callback + "({ \"return\": \"Success\" })");
                }
            }
            catch (Exception exc)
            {
                //hopefully this error doesn't contain any quotes... you know?
                context.Response.Write(callback + 
            "({ \"return\": \"" + exc.Message + "\" })");
            }
        }

        private void SaveData(string value)
        {
            //do something with the var1 posted to us
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
So what we effectively have here is the setup for ASP.NET cross domain Ajax calls using jQuery.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;How to do Cross-domain Calls to Others' Servers: YQL&lt;/h4&gt;&lt;br /&gt;
What if you need to do a get, but don't have the ability to make the page it's posting to return a JSONP response? Using YQL is a great way to achieve this.&lt;br /&gt;
&lt;br /&gt;
YQL is a way to query the internet like it is a database. For example, one could easily run:&lt;br /&gt;
&lt;pre&gt;select * from html where url="http://www.microsoft.com"&lt;/pre&gt;&lt;br /&gt;
and receive a JSONP return containing all of the site's HTML. You could also do the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;select * from html where url="http://www.mircorosft.com?var1=var1value"&lt;/pre&gt;&lt;br /&gt;
and &lt;code&gt;HTTP GET &lt;/code&gt;values to the server. YQL does not allow this to happen on any area of any site that is blocked by the &lt;i&gt;robots.txt&lt;/i&gt; file. Here's the full example code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;//feel free to add querystring vars to this
var myurl="http://www.example.com/get-post.ashx?var1=var1value&amp;amp;callback=?";
//make the call to YQL 
$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
                "q=select%20*%20from%20html%20where%20url%3D%22"+
                encodeURIComponent(myurl)+
                "%22&amp;amp;format=xml'&amp;amp;callback=?",
        function(data){
          if(data.results[0]){
            //this data.results[0] is the return object you work with, 
            //if you actually want to do something with the returned json
            alert(data.results[0]);
          } else {
            var errormsg = '
Error: could not load the page.
';
            //output to firebug's console
            //use alert() for other browsers/setups
            conole.log(errormsg);
          }
        }
      );&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-887640790652174112?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/UJynSOGmT_E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/887640790652174112/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/making-cross-domain-jquery-ajax-calls.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/887640790652174112?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/887640790652174112?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/UJynSOGmT_E/making-cross-domain-jquery-ajax-calls.html" title="Making Cross Domain jQuery AJAX Calls" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/making-cross-domain-jquery-ajax-calls.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkYMQno7cCp7ImA9Wx5WFUo.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-5669745103354157768</id><published>2010-09-27T02:02:00.000-07:00</published><updated>2010-09-27T02:03:03.408-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T02:03:03.408-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="iPhone Development" /><title>Getting Started with iPhone and iOS Development</title><content type="html">&lt;span style="font-size: large;"&gt;&lt;b&gt;Introduction &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
This is a first in a series of articles to get some one up and running with iOS  development. iOS is the operating system that runs on the iPhone, iPad, and iPod Touch. While I will use an iPhone for my example code you could apply the code to all three devices.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/GetStarted.png" /&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Pre-requisites&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
To take advantage of this article you’ll need to already have an understanding of object oriented concepts and you’ll need to know a C-language (C, C++, C#) and know what is meant when I use terms such as object, class, function, method, variable, and so on.  I’m making the assumption that you have never looked at Objective-C.  I’ll introduce you to the Objective-C language and then will walk you through some programming scenarios that I think will best get you started. As things are in any programming environment there will be more than one way to get a task accomplished or more than one syntax to express something. Exhaustively presenting all the possible ways that something can be expressed is not reasonably possible.  So keep in mind that there are other ways of accomplishing what I explain here. &lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Selecting Hardware&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
A minimally sufficient development environment for iOS applications is composed of just an Intel based Mac. Owning an iPhone, iPod, or iPad is optional but extremely helpful.&lt;br /&gt;
&lt;br /&gt;
If you are looking for the absolute best hardware to use for developing for iOS it’s easy to say “get the top of the line Power Mac with all the options you can.” But for most of us (myself included) there’s going to be a cost constraint when selecting the development hardware that you use. The absolute minimum hardware configuration that you need will be an Intel based Mac running Snow Leopard. The least expensive Mac that you can purchase new is the Mac Mini. Compared to the price of the lowest cost PC that you can purchase the Mac Mini will look quite pricy. But I’d suggest shelling out a little more money to get a portable computer.  With the Mac Mini you’ll be confined to developing when you are in the room in which it is setup. With one of the Mac Books you might also find yourself developing when you are relaxing in front of the TV or in some other comfortable spot. &lt;br /&gt;
&lt;br /&gt;
Depending on your needs if you find that you don't need the latest version of the iPhone for your intended applications it's a good idea to shop around for bargins when Apple is releasing either a new iPhone or new Macs. I was able to acquire an inexpensive iPhone from some one else that was upgrading and found a Mac Mini on sale from a store that was clearing their shelves for newer units. (I've since then moved onto a Mac Book Pro after wanting to be able to develop from othe rooms in the house) &lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/MinimalDev.png" /&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;My initial setup was made of an intel Mac Mini I found on sale and a contract free iPhone I purchased from some one upgrading to the next generation phone&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
You don’t need to have an iPhone, iPod, or iPad to get started (hereon I will collectivly refer to these devices as iOS devices). The SDK comes with simulators (or emulators if that’s the terminology that you are accustomed to). But the simulators have limitations; you’ll find that you’ll want to have real hardware when you are developing anything that uses an accelerometer.&lt;br /&gt;
&lt;br /&gt;
If you plan to use real hardware for your testing it’s not sufficient to have just the needed hardware and software. You will also need to have a subscription to Apple’s iPhone Development Program (cost about 99 USD per year). &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Do I need to have a Macintosh?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
I get a lot of traffic to my personal web site because of a service I reviewed that was designed to allow those without a Mac to do iPhone development.  I don’t want to go into a discussion of the service here so I’ll just tell you yes, it is mandatory that you have a Macintosh.  The only sanctioned hardware for iPhone development is an Intel based Macintosh. Don’t waste your time trying to circumvent this.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Installing the SDK&lt;/b&gt;&lt;br /&gt;
The iPhone SDK is already present on the installation disk for OS X Snow Leopard. Don’t use that one. There will always be a more up to date version available for download. Weighing in at about 3 gigs the SDK could take some time to download depending on the speed of your connection.  To get the installation go to http://developer.apple.com. You’ll see a link to the iPhone Dev center. Clicking on it will take you to the page for the SDK download. Apple sometimes has beta versions of the SDK available for download available. But unlike the current version of the SDK the beta versions are not available for all to download. You must be a registered developer with a subscription to have access to them. &lt;br /&gt;
&lt;br /&gt;
The DMG for the SDK will download and automatically mount.  Run the installation and after it finishes you’ll be ready to get stated with development. &lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Getting Started with Objective-C&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Programs created for the iPhone are written in Objective-C. Objective-C is often described as a strict superset of the C language. Others call it C with object oriented concepts applied. The first time I saw it I have to say I felt like I had no idea what I was looking at. It doesn’t look like any other programming language that I know. But after you get through your first few programs you’ll find it to be much easier to follow.  Being a strict superset of C if you already have algorithms that are written in C you should be able to port them over to the iPhone. The following chart shows some expressions that mean close to the same thing in C and Objective-C.&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
C/C++&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
Objective-C&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-preprocessor"&gt;#include&lt;/span&gt;&lt;span class="code-preprocessor"&gt; &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;library.h"&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-preprocessor"&gt;#import&lt;/span&gt; “library.h&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;&lt;/span&gt;&lt;/code&gt;”&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-keyword"&gt;this&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;self&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-keyword"&gt;private&lt;/span&gt;:&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;@private&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-keyword"&gt;protected&lt;/span&gt;:&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;@protected&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-keyword"&gt;public&lt;/span&gt;:&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;@public&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;Y = &lt;span class="code-keyword"&gt;new&lt;/span&gt; MyClass();&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;Y = [[MyClass alloc] init];&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
&lt;code&gt;&lt;span class="code-keyword"&gt;try&lt;/span&gt;, &lt;span class="code-keyword"&gt;throw&lt;/span&gt;, &lt;span class="code-keyword"&gt;catch&lt;/span&gt;, &lt;span class="code-keyword"&gt;finally&lt;/span&gt;&lt;/code&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;code&gt;@try, @throw, @catch, @finally&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;i&gt;&lt;b&gt;Some expressions that mean the same (or almost the same) in C/C++ and Objective-C.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
Within Objective-C  both your class definitions and objects instantiated from those classes are instances of a struct called ‘id.’ The definition of id is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;typedef struct  objc_object {
     Class* isa;
} *id;&lt;/pre&gt;&lt;br /&gt;
Since this is the foundation of all objects within Objective-C you will find an “isa” member on every Objective-C object that refers to its type data.  Instances of “id” are all pointers so you can distinguish one from another by comparing their addresses. There is a special id value named nil whose pointer value is set to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Classes&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
In Objective-C you declare a class’s interface separate from its implementation. You have probably seen a similar separation of interface and implementation in C++ programs where a classes interface is defined in a *. h file which the implementation is in a *.cpp file. Likewise in Objective-C the interface is defined in a *.h file and its implementation in a *.m  file.&lt;br /&gt;
&lt;br /&gt;
Every class you create in Objective-C should either directly or indirectly derives from the NSObject base class. The base class doesn’t look to do much at first glance but it contains functionality that the runtime need for interacting with the object. You don’t want to have to implement this functionality yourself. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Class Interface Declaration&lt;/b&gt;&lt;br /&gt;
To declare a new class you start off by declaring the classes interface. The class interface declaration starts with the @interface compiler directive and ends with the @end  directive.  You’ll see a set of open and close curly-brackets within a class interface declaration.  Just remember that the closing bracket is not the end of the class interface definition!  Here is a generic class definition&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;@interface YourClassName: TheSuperClass
{
     instance members
}
Message Declarations
 
@end&lt;/pre&gt;The declaration for the instance members doesn’t differ from one you might expect from one of the other C languages. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;BOOL  isValid;
float width;
NSString* name;&lt;/pre&gt;&lt;br /&gt;
A class automatically has access to all the classes in its inheritance ancestry. So you can refer to classes of any of its base types without doing anything special. If you are referring to a class that is not in its inheritance chain then you will need to make a forward declaration for that class. The following makes a forward reference to two classes, Employee and Accountant.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;@class Employee, Accountant;&lt;/pre&gt;The declaration of messages is different. A message can either be associated with the class or associated with an instance of that class. Class methods are preceeded with a plus (+) while instance methods are preceded with a minus (-).  The default return type of class messages are id instances. To change the return type to something else you’ll need to put a return type in parens just before the class name. Note that this is the same syntax that you would use to cast a variable from one type to another.  Here’s an example of a simple message declaration&lt;br /&gt;
&lt;pre&gt;- (int)GetSize;&lt;/pre&gt;&lt;br /&gt;
Message parameters immediately follow a message name. They are colon delimited and their types are indicated with the same syntax that one would use to cast to a different type. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;-(float) Power:(float)width:(float)height; &lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Class Implementation&lt;/b&gt;&lt;br /&gt;
The class implementation is in a *.m file.  Just as you would in C++ you will need to include the classes header file when you are writing the implementation. Instead of using an #include directive to do this you will use an #import directive.  The syntax for declaring the implementation is similar to the syntax for declaring the interface, only you replace the @interface directive with an @implementation directive.  One possible syntax for starting off the implementation follows.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#import “YourClass.h”
@implementation YourClass
   your message implementations go here
@end&lt;/pre&gt;&lt;br /&gt;
Optionally you could re-declare the instance variables and super class here, but it’s not necessary.  The message implementations start off the same way as a message. But instead of terminating the declaration with a semicolon(;) you append a curly bracket pair enveloping your implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;- (float)square:(float)x
 
{
     return x*x;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Methods, Messages, and Object Communication&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Most object oriented material you come across will refer to messages being sent among objects.  Most of the time you’ll see this implemented through methods.  In most cases the words method and message can be used interchangeably. Objective-C sticks with using the terminology “message.” So I’ll adhere to that standard within this document.&lt;br /&gt;
&lt;br /&gt;
The syntax for sending a message (which means the same thing as  “calling a method”) is to enclose the name of the target object and the message to be passed within square brackets. So in C++/C# you may have send a message using the following syntax&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;myObject.SomeMethod();&lt;/pre&gt;&lt;br /&gt;
Within Objective-C you would accomplish the same thing with the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;[myObject SomeMethod];&lt;/pre&gt;&lt;br /&gt;
Passing parameters to messages is a little different than what you are used to. For one parameter things make perfect sense and don’t need much of an explanation. Just place a colon after the name of the message followed by the parameter value. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;[myObject SomeMethod:20];&lt;/pre&gt;&lt;br /&gt;
When you want to pass more than one argument things could potentially look messy. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;[myObject SomeMethod:20:40];&lt;/pre&gt;&lt;br /&gt;
As you more arguments are added to a message the code could potentially become less readable; I wouldn’t expect a developer to memorize the parameters that a method takes. Even if he or she did then there’s still mental effort involved in identifying what parameter is associated with which value. For clarity you could do something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;[myObject SomeMethodA:20 B:40];&lt;/pre&gt;&lt;br /&gt;
In the above it appears that I’ve named the parameters ‘A’ and ‘B’ and that parameter ‘A’ is oddly concatenated to the message name.  What you may not have realized is that the parameter names and colons are all parts of the message name. So the full name of the message is SomeMethodA:B:.&lt;br /&gt;
&lt;br /&gt;
If a message returns an object a message you can pass a message to the returned message through a nested call. In C/C# you would have code that looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;myObject.SomeMessage().SomeOtherMessage();&lt;/pre&gt;&lt;br /&gt;
Whereas in Objective-C the same thing would be accomplished with this&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;[[myObject SomeMessage] SomeOtherMessage];&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Prototypes&lt;/b&gt;&lt;br /&gt;
Prototypes are much like weakly implemented interfaces. In other programming languages if a class implements an interface then within the classes declaration there is a statement that shows that it is implementing a certain interface. With prototype the class only needs to implement certain methods to conform to a prototype. There doesn't need to be any mention to the prototype definition that it is conforming to. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Class Instantiation and Initialization&lt;/b&gt;&lt;br /&gt;
An instance of a class is instantiated using the alloc method of the class. alloc will reserve the memory needed for the class.  After the memory is allocated you’ll want to initialize it.  Every class that has instance members will need to have an init method defined. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;myObject = [[MyClass alloc] init];&lt;/pre&gt;The first time I saw the above pattern I made the mistake of thinking that it was equivalent to the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;myObject = [MyClass alloc];
[myObject init];&lt;/pre&gt;&lt;br /&gt;
They are not equivalent. The value returned by init may not be the same as the value returned by alloc. So you should always combine the alloc and init messages when doing the assignment.&lt;br /&gt;
&lt;br /&gt;
When you implement your own initializer for a class the initializer should either return self to signal that it was successful or nil to signal that it was unsuccessful. The return type for an initializer should always be id. This is to explicitly show that the type returned by the initializer may be of another type.&lt;br /&gt;
&lt;br /&gt;
If you need to pass a parameter to your initializer then it will generally have init as the prefix for the initializer name. For example if I had an initializer that required a date I may call it initWithNSSDate.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Memory Management&lt;/b&gt;&lt;br /&gt;
Objective-C classes keep track of a reference count. The count can be read through -(NSUInteger)retainCount;  at any time (though other than satisfying cutiousity there aren't many scenarios that call for needing to do this). When the reference count of an object reaches zero then it is released. For the most part the details of this reference counting are abstracted away and the methods related to reference counting are presented as methods for taking ownership of an object (which increments the reference count) or relinquishing ownership of the object (decrementing the reference count).&lt;br /&gt;
&lt;br /&gt;
The general rule is that if you've created an object with any method prefixed with alloc or new or had copied the object from an existing object then you are responsible for releasing the object. If you've taken ownership of an object (with retain) then you must also release it. Note: If you don't own it then don't release it. Calling autorelease on an object will add it to a pool of objects to be released and deallocated at some point in the future.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Copying an Object&lt;/b&gt;&lt;br /&gt;
When copying an object if that object's member variables contain pointers to other objects there are two ways to go about copying it. On way is to copy the pointers from the original object to the object being created. This method of copying (also called a shallow copy) will result in both the new object and the original object to share the same instances of objects that make up their members. So if a change occurs within a member object of one class it will also afect the member within the other since they are really the same instance. The other method of copying is to create new isntances of the member objects when the new object is created. The end result of this is that changes to an instance object on one instance of the object will have no impact on the other. The original and copied object are completly independent in this case. Both approaches have their advantages and disadvantages when one looks at the result that the two copy methods in terms of memory consumption and potential side affects. There can exist scenarios that have a mixture of shallow and deep copy techniques. If you created a class and implemented a deep copy but one of the instance members implements a shallow copy then you could end up with an instance member of an instance member refering to the same object as an instance member of an instance member in the object you just copied. (that's potentially confusing, but I can think of no clearer way to say it)&lt;br /&gt;
&lt;br /&gt;
There should be consistency between how a class's copy method works and how the classes set methods work. If the set method on the class creates new new instances when performing assignment the the copy method should be a deep copy. If the set method saves the instance that is passed to it then the copy method should be a shallow copy. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;-(void)SetMyMemberVariable:(id)newValue
{
    [myMmeberVariable autorelease];
    myMemberVariable = [newValue copy];
}&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Implementation of a set method that creates a new isntance of an object.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;-(void)SetMyMemberVariable:(id)newValue
{
    [myMemberVariable autorelease];
    myMemberVariable = [newValue retain];
}&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Implementation of a set method that copies a reference to existing instance of object.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Low Memory Conditions&lt;/b&gt;&lt;br /&gt;
The user interface for your iOS programs will be controlled through a class derived from UIViewController. There are two methods on the class that are involved in low memory handling. One is didReceiveMemoryWarning which was in existence before iOS 3. As of iOS version 3 and later there is a method named viewDidUnload. When the device is low on memory the OS will destroy the views if it knows that the views can be reloaded and recreated again. When this method is called your class should respond by releasing its references to view objects. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Constructing Hello World&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
If you’ve skipped the Objective-C introduction and tried to jump straight into creating a program you are about to be lost in a sea of cryptic notation and nonsensical glyphs. I’ve you’ve read though the primer then you’ll have no problem understanding what follows. We are going to build a “Hello World” program. The program will have one button and a text field. When someone clicks on the button the text field will display the words “Hello World.” I’ll also be taking this as an opportunity to cover some concepts that would otherwise not make sense in the absence of this exercise.&lt;br /&gt;
&lt;br /&gt;
Using either the Finder or Spotlight startup Xcode. When the Xcode welcoming screen appears select the option to “Create a new Xcode project”.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/WelcomeToXcode.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that “Application” is selected under iPhone OS to see a list of the type of iOS projects that you can create.   Select “View-based Application” and make sure that the “Product” dropdown has iPhone selected. Once you’ve done this click on the “Choose” button end type “MyHelloWorld” when prompted for the name of the project. &lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/NewProject.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
A new project is generated and at this time is in a state such that it can be run.  Make sure your iOS device is not  connected to the computer (if you try to deploy to your own personal device right now it will fail) and select “Build and Run.” Your project will be compiled and copied to the emulator and run. The result is pretty boring looking; it is just a blank screen since we haven’t added anything to the user interface yet.  You can click on the red button in Xcode to stop the program When the program terminates you’ll see it’s icon in the iPhone simulator. It’s just a plain white rounded square. Let’s change that.&lt;br /&gt;
&lt;br /&gt;
If you want to change the program’s icon make a new 57x57 pixel PNG image. Don’t worry about rounding the corners or doing the other things that make it look iPhone styled; that will happen automatically for you. Once you’ve made your image in your editor of choice navigate to it in the Finder. Click-and-drag the icon to the Resources folder in Xcode. You’ll be asked whether you want to copy the file into the project’s folder or if you want to only copy a reference. It is usually a good idea to copy the file.&lt;br /&gt;
&lt;br /&gt;
In the Resources folder find the file HelloWorld-Info.plist and click on it. A *.plist file is a property list that contains some general information about the application. Clicking on the plist file will cause the property editor to open. One of the available properties is named “Icon.” Double-click on the property sto begin editing it and type the name of your icon file. The next time you build and run your application after you close it you’ll see your icon.  &lt;br /&gt;
&lt;br /&gt;
The Xcode window is divided into three panes. The horizontal pane on the top has a list of files in it. Look for the file named MyHelloWorldViewController.XIB and double-click on it. This will open up the interface builder.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/InterfaceBuilder.png" /&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;The Interface Builder windows.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Among other windows you should see a blank iPhone surface ready for you to layout controls on it. If you don’t see this then double click on the “View” icon in one of the windows that appears to display the layout surface.  Scroll down in the “Library” window until you see the Text-Field control. Drag an instance of this control onto the design surface somewhere  on the upper half of the screen. Also drag a “Round Rect Button” to the design surface somewhere close to the text field.&lt;br /&gt;
&lt;br /&gt;
Select the button and then go to the Identity tab in the properties window.  Set the Name for the button to “MyButton”. Select the text field and set its name to “MyText”. Save your changes and then go back to Xcode and run your project again. This time you’ll see the text field and the button on the screen. &lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/PropertiesTabs.png" /&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;The tabs from left to right are Identity, Connections, Size, and Identity. &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
We want to change the program so that when the user clicks on the button the text “Hello World” displays in the text field.  But if you look through our source code it will become apparent that  neither the button nor the text field are immediately available for us to  manipulate in the code. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;IBAction and IBOutlet – Responding to Actions and Providing Feedback&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
We can have the button send a message to our code when it is clicked. We need to declare an IBMethod  in our code so that the button has something to which it can send its message.  Open “HelloWorldViewController.h” and in the line after the closing bracket for the interface definition add the following. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;- (IBAction) myButtonWasClicked:(id)sender;&lt;/pre&gt;&lt;br /&gt;
As you may have gathered from reading the Objective-C primer you’ll also need to add an implementation for this method to the HelloWorldViewController.m file. In the line after the @implementation directive type the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;- (IBAction) myButtonWasClicked:(id)sender
 
{
     NSLog(@”The button was clicked”);
}&lt;/pre&gt;&lt;br /&gt;
Open the HelloWorldViewController.xib in the interface builder. Holding down the control key click-and-drag from your button to the “File’s Owner” icon. A sub-menu appears allowing you to select a method. Select the myButtonWasClicked method.&lt;br /&gt;
&lt;br /&gt;
Run the project and then type Shift-Command-R in Xcode to open the console. Whenever you click on the button you will see the text “The button was clicked” appear.&lt;br /&gt;
&lt;br /&gt;
Our final goal was to display a message on the screen to the user; there’s more work to be done. While the IBAction methods allowed us to receive notification of something happening they don’t help much in actively changing the contents of the text field. We need to first get or hands on an instance of that text field. But the text field isn’t declared within our code. It is declared inside of the XIB file.  To get a reference to the text field we must declare an outlet. An outlet is a variable that is automatically assigned a value by Cocoa at runtime.&lt;br /&gt;
&lt;br /&gt;
Within the header file for the view type the following under the method that you created.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;@property (retain) IBOutlet UITextField *myTextBox;&lt;/pre&gt;&lt;br /&gt;
Copy the same thing into the area for the instance variables and remove the @property (retain) part from it.&lt;br /&gt;
&lt;br /&gt;
In the implementation add the following&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;@synthasize myTextBox;&lt;/pre&gt;&lt;br /&gt;
The code in the myButtonWasClicked method also needs to be changed. Within this method set the text on the myTextBox instance to “Hello World”.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;myTextButton.text=@”Hello World”&lt;/pre&gt;&lt;br /&gt;
The next step is to associate the text field with this property from the interface builder.  From within the interface builder right-click on the “File’s owner” module and find the myTextBox outlet. While holding down the control key click-and-drag from the outlet to the text field.  If you run the program now when the button is clicked “Hello World” will appear in the text box. We've only looked at the textbox. But the interactions with many other visual controls is the same. If you add a slider to the interface, an IBAction method to my class, and then associate the method with the slider I can receive notifications when the slider value is changed.&lt;br /&gt;
&lt;br /&gt;
The last step is a cleanup task. As described in the low memory section if the iPhone becomes low on memory it will begin to destroy views to clear up memory. Well need to clear our references to the view objects when this happens. Also when the view is being deallocated we need to release ownership of the view objects we reference in our code. You can see how bow both of these were implemented in the -(void)viewDidUnload and -(void)dealloc methods in the full code below.&lt;br /&gt;
&lt;br /&gt;
The source code below contains both our the helloWorld functionality along with displaying the value of a slider.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#import 
@class NSTextField;
 
@interface HelloWorldViewController : UIViewController {
    IBOutlet UITextField * myTextBox; 
    IBOutlet UISlider    * mySlider;
    IBOutlet UITextField * mySliderText;
}
@property (retain) IBOutlet UITextField * myTextBox;
@property (retain) IBOutlet UISlider    * mySlider;
@property (retain) IBOutlet UITextField *mySliderText;
 
- (IBAction) myButtonWasClicked:(id)sender;
- (IBAction) mySliderWasMoved:(id)sender;
 
@end
&lt;/pre&gt;&lt;i&gt;&lt;b&gt;The class interface declaration from HelloWorldViewController.h&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre&gt;#import "HelloWorldFinalViewController.h"
 
@implementation HelloWorldFinalViewController
@synthesize myTextBox;
@synthesize mySliderText;
@synthesize mySlider;
 
- (IBAction) myButtonWasClicked:(id)sender
{
    NSLog(@"The button was clicked");
    myTextBox.text=@"Hello World";
}
- (IBAction) mySliderWasMoved:(id)sender
{
    NSLog(@"The Slider was moved");
    UISlider *slider = (UISlider*)sender;
    float sliderValue = [slider value];
    NSString* sliderValueText = [NSString stringWithFormat:@"The slider's current value is %f", sliderValue];
    mySliderText.text=sliderValueText;    
}
 
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
 
 //View is being destroyed to free memory. Clear
 //out our references to view obejcts. 
- (void)viewDidUnload {
    self.textBox=nil;
    self.mySliderText=nil;
    self.mySlider=nil;
}

// during a dealloc release our hold on the view objects
-(void)dealloc{
    [myTextBox release];
    [mySliderText release];
    [mySlider release];
    [super dealloc];
}
 
@end
&lt;/pre&gt;&lt;i&gt;&lt;b&gt;The class implementation from HelloWorld.m&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The two things to take from this example program are how to get a reference to a UI object created in the interface builder, and how to receive messages from UI objects. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Deploying to a Real Device&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Now that you’ve written your first program those of you with a real device probably want to deploy it to that device.  Before you can copy your program to a real device you *must* complete the App store registration with Apple. Until you do this you will not be able to complete the provisioning process.&lt;br /&gt;
&lt;br /&gt;
Connect your iOS device to your computer. In Xcode change the dropdown so that instead of attempting to run the program in the simulator Xcode will run the program on an actual device.  When you attempt to run the program you’ll get a failure notice stating that the device doesn’t have a provisioning profile. If you select “Install and Run” from the error dialog you’ll encounter another failure about the provisioning profile not being found.&lt;br /&gt;
&lt;br /&gt;
To provision your device you’ll need to have your developer certificate. Go to the iPhone Developer Portal (http://developer.apple.com/iPhone) and log in with your apple ID. On the left hand side there is a link that will take you to the provisioning page. Click on the link and select “Launch Assistant” from the bottom of the page.  Click on “Continue” when the Development Provisioning Assistant welcome window opens. On the next screen you’ll have toidentify the application you are developing. Click on “Create a new App ID” and select “Continue.” On the next string you enter a description or name for the application (be creative!). Following that you have to identify the Apple device that you are using for development. Select “Assign a new Apple device.” You’ll be asked for the device’s description and Device ID.&lt;br /&gt;
&lt;br /&gt;
The Description can be almost any name. If you only have one iOS device then you really won’t care what you put in there. If you have more than one then you’ll want to put something here that will allow you to easily identify which device you were using at the time. The Device ID can be found in the Xcode Organizer. Switch back to Xcode and select the Window menu and then select “Organizer.” When the organizer opens you will see your iOS device listed on the left. Select it. You may see a button labeled “Use this device for development.” If you do then click on it.  When your device information is displayed at the top of the screen look for the value labeled “Identifier” and copy it to your clipboard. Go back to the  Development Provisioning Assistant and past it in Device ID and click on Continue. You’ll see a confirmation that your certificate was created. When you go to the next screen you need to assign a name to the profile you just created. After clicking on Continue two more times you will be able to download your provisioning certificate.  After downloading your certificate go back to the Xcode Organizer and click on the “+” button in the provisioning area. In the window that opens navigate to your provisioning file and select it. Once you do this your device will be provisioned.  You should be able to run the project on your device now. Every now and then when I go through the process of deploying the provisionin certificate to the device it doesn’t work. When this happens I have to disconnect and then reconnect my iDevice one or two times before it will work. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Watch Out, Provisioning Profiles Do Expire!&lt;/b&gt;&lt;br /&gt;
The provisioning profile copied to your device is only good for about three months. After it expires any executables on your device associated with the profile will cease to function. If you want to see when a device's provisioning profile expires you can view it in the Settings menu. Navigate to Settings-&amp;gt;General-&amp;gt;Profile to view your current provisions. &lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;String Parsing, Formatting, and other Text Manipulation&lt;/span&gt;&lt;br /&gt;
The base class for strings is the NSString  class. The NSString class is immutable, so the string it contains doesn’t change. There is also a subclass named NSMutableString whose contents can be changed. The NSString  class stores Unicode characters. The length of a string can be probed through its length method and the character at a specific location in the string can be probed with the characterAtIndex method.&lt;br /&gt;
&lt;br /&gt;
There are several ways that a string can be initialized.  One way (that you’ve already seen by now) is to envelope literal text within a quotation marks and prefix it with the at-sign (such as @”Hello World!”). If you need to create a string from other data (such as an integer value) you can use the  class method stringWithForm. The method takes a formatting string that is similar to the formatting strings that you may have used in C/C++.  The following code results in the string “There are 12 items in a dozen.”&lt;br /&gt;
&lt;pre&gt;NSString* myString = [NSString withStringFormat:@”There are %d items in a dozen.”, 12];&lt;/pre&gt;If you have a numeric value represented as a string you can easily convert it back to a numeric value with one of the xxxValue methods (where xxx can be int, integer, double, bool, float, or long).&lt;br /&gt;
&lt;br /&gt;
There are a lot of other string manipulation methods available and I can’t cover them all here. But I encourage you to glance through the NSString documentation to learn more about the string manipulation methods available.  I well use a few more of the available methods as relevant within this document.&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Data Persistence&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
There are multiple ways of persisting data on an iOS device.  If you wanted to use traditional C-language IO you could use fopen and its related functions to manipulate files. I won’t cover that here. Instead I’ll cover a few of the solutions specific to iOS.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Getting your Application’s Storage Path&lt;/span&gt;&lt;br /&gt;
On iOS devices your application is sandboxed.  There are only a few folders that your application can write to. There is a /Documents folder for information that you need to persist and be backed up regularly.  There’s a /Cache folder where you can place information that should be available between launches but not backed up by iTunes. And there is a /tmp folder for information you only need while the application is running. It cannot read or write to any other location on the device. You can get the path to your application’s /Documents folder using the function NSSearchPathForDirectoriesInDomain(). This function exists for both iOS and Mac OS X. You’ll find that it won’t work with all of the options available; either because the option isn’t supported on iOS or because your application doesn’t have permission to use certain options.&lt;br /&gt;
&lt;br /&gt;
This function returns an array of directories that meet a given criteria. Our initial use of it here is to retrieve a single directory so when we retrieve the path to our Documents folder we will get an array of one item. The first argument that we must pass to the function is the constant NSDocumentDirectory. As the name implies this tells the function that we want the Documents folder. The second parameter is the constant NSUserDomainMask. This specifies that we want to restrict our search to our applications folder.&lt;br /&gt;
&lt;pre&gt;NSArray *myPathList =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *myPath = [myPathList  objectAtIndex:0];&lt;/pre&gt;&lt;br /&gt;
To construct a file name for our reading or writing purposes we only need to concatenate a file name to our path. NSString has a method just for that purpose.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;NSString *myFilename = [myPath stringByAppendingPathComponent:@”fileName.txt”];&lt;/pre&gt;&lt;br /&gt;
For temporary files there is a function that takes no parameters and returns a path that can be used for temporary files. Its name is NSTemporaryDirectory();&lt;br /&gt;
&lt;br /&gt;
Having constructed your file name you can use it for one of the data persistence APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;PList&lt;/b&gt;&lt;br /&gt;
PList (or properly list) are easy to use. If you make an in-memory  hierarchy of data using only a certain set of objects then that  hierarchy can be written to a file or loaded foam a file all at once.&amp;nbsp;  As the developer you don’t have to worry about serializing your data.  This is done for you. A disadvantage that come from using this solution  is that even if you make a small change to your data you must rewrite  the entire file; you can’t make incremental changes. &amp;nbsp;&amp;nbsp;The following are  the classes that you can use when making an object hierarchy for a  PList:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;NSArray&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSData&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSDate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSDictionary&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;MutableArray&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSString&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSMutableString&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSNumber&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;After you’ve built your object hierarchy you can save the structure and its data to a file using the &lt;code&gt;writeToFile&lt;/code&gt;  method. It needs a file name and a value for the atomically parameter.  If Atomically is set to yes then instead of saving directly to the  target file the data will be stored to a temporary file and then moved  to the destination file name. It takes longer, but is much safer. If the  device crashes you are less likely to end up with a file in a corrupted  state.&amp;nbsp;&amp;nbsp; To load the contents of the file we can just instantiate the  root element and use the initialization method &lt;code&gt;initWithContentsOfFile&lt;/code&gt;.  This method takes the file path as it’s only argument and will take  care of building the entire hierarchy&amp;nbsp; as it populates the data. &lt;br /&gt;
In the following code example I made use of&amp;nbsp; a PList to save data to a  file. I made a simple interface with three textboxes (for data) and two  buttons to invoke the save and load functionality. &lt;br /&gt;
While not visisble very where there is also a label control below the  buttons. When the data is loaded or saved the path to the file is  displayed there. When the save button is clicked the contents of the  text boxes are copied to an NSArray and saved to a files with the &lt;code&gt;writeToFile&lt;/code&gt; method. When the load button is clicked a new NSArray is created and initialized with the &lt;code&gt;initWithContentsOfFile&lt;/code&gt; method. &lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/data.png" /&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;This is a screenshot of the data persistence example being built. &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
If you want to see whether or not the file is really saving run the program, save some text, and then close the program. If you run it again it will be able to reload the data.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#import &lt;uikit&gt;
 
@interface DataPersistenceExampleViewController : UIViewController {
    IBOutlet UITextField* textBox00;
    IBOutlet UITextField* textBox01;
    IBOutlet UITextField* textBox02;
    IBOutlet UILabel* storageLocationLabel;
    
    NSString* storagePath;
}
 
@property (retain) IBOutlet UITextField *textBox00;
@property (retain) IBOutlet UITextField *textBox01;
@property (retain) IBOutlet UITextField *textBox02;
@property (retain) IBOutlet UILabel *storageLocationLabel;
@property (retain) NSString *storagePath;
 
- (IBAction)saveButtonClicked:(id)sender;
- (IBAction)loadButtonClicked:(id)sender;
 
@end&lt;/uikit&gt;&lt;/pre&gt;Class interface declaration for data persistence example.&lt;br /&gt;
&lt;pre&gt;#import "DataPersistenceExampleViewController.h"
 
@implementation DataPersistenceExampleViewController
@synthesize textBox00;
@synthesize textBox01;
@synthesize textBox02;
@synthesize storageLocationLabel;
//@synthesize storagePath;
 
- (IBAction)saveButtonClicked:(id)sender
{
    NSArray*    valueList = [NSArray arrayWithObjects: textBox00.text,textBox01.text, textBox02.text,  nil];
    
    NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *myPath = [myPathList objectAtIndex:0];
    storagePath = [myPath stringByAppendingPathComponent:@"myData.txt"];
    
    storageLocationLabel.text = storagePath;
    
    [valueList writeToFile:storagePath atomically:true];
 
}
 
- (IBAction)loadButtonClicked:(id)sender
{
    
    NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *myPath = [myPathList objectAtIndex:0];
    storagePath = [myPath stringByAppendingPathComponent:@"myData.txt"];
    NSArray* valueList = [[NSArray alloc] initWithContentsOfFile:storagePath];
    
    textBox00.text = [valueList objectAtIndex:0];
    textBox01.text = [valueList objectAtIndex:1];
    textBox02.text = [valueList objectAtIndex:2];    
}
 
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
    self.textBox00=nil;
    self.textBox01=nil;
    self.textBox02=nil;
    self.storageLocationLabel=nil;
}
 
 
- (void)dealloc {
    [textBox00 release];
    [textBox01 release];
    [textBox02 release];
    [storageLocationLabel release]
    [super dealloc];
}
@end
&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Implementation for the Data Persistence example.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Writing Files with Archivers&lt;/h3&gt;While PList are easy to manipulate they data types that you can store  in them are rather basic.&amp;nbsp; Archivers can write objects of any type to a  file as long as that object conforms to the NSCoding protocol. The &lt;code&gt;NSCoding&lt;/code&gt; defines messages for reading and writing an objects state.&amp;nbsp;&amp;nbsp; When an object is being saved to a file its &lt;code&gt;encodeWithCoder:&lt;/code&gt;  method is called so that it can express its state information. During  unarchiving (When the object is being read back from the file) the &lt;code&gt;initWithCoder:&lt;/code&gt;  method is called and the information that had previously been saved by  the archiver is provided so that the object can reinitialize itself. &lt;br /&gt;
Both messages receive on parameter of type &lt;code&gt;NSCoder&lt;/code&gt;. The &lt;code&gt;NSCoder&lt;/code&gt;  object has various methods for encoding different data types such as  Booleans, bytes, strings, and other types of objects. For each encoding  method there is also a decoding method. &lt;br /&gt;
&lt;br /&gt;
&lt;table border="1"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;br /&gt;
&lt;b&gt;Encoding Method&lt;/b&gt;&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
&lt;b&gt;Decoding Method&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
encodeBool:forKey&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
decodeBoolForKey&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
encodeInt32:forKey&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
decodeInt32ForKey&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
encodeArrayOfObjCType:count:at&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
decodeArrayOfObjCType:count:at&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Working with the Accelerometer&lt;/span&gt;&lt;br /&gt;
The accelerometer within the device detects forces of acceleration.  The force of gravity on Earth is equal to the force that an object would  experience if it were accelerating at 9.81 meters/second^2. So a device  that isn’t being moved will detect a force in the direction that  gravity is pulling it. If the device were in a free-fall it’s  accelerometer would have a reading that is close to zero (take my word  for this and please don’t test it by dropping your device). The  accelerometer’s reading are composed of measurements along the X, Y, and  Z axis, so the accelerometer in the iPhone can detect movement in any  direction. &lt;br /&gt;
Every application has access to a single &lt;code&gt;UIAccelerometer&lt;/code&gt;  instance to read the accelerometer data. You don’t instantiate this  instance directly. Instead you retrieve it through the class method  sharedAccelerometer on the &lt;code&gt;UIAccelerometer&lt;/code&gt; class.&amp;nbsp; Once you  have an instance of this class you provide a delegate that will receive  the data and an update interval. The smallest update interval is 10  milliseconds which will cause 100 updates per second. Most applications  won’t need updates this often. When you no longer need accelerometer  data you can set the delegate to nil to stop receiving updates. You  shouldn’t&amp;nbsp; leave the update mechanism active when you don’t actually  need accelerometer data. Doing so can contribute to a faster draining  battery. &lt;br /&gt;
The delegate method that you implement is named &lt;code&gt;accelerometer:didAccelerate:&lt;/code&gt;. When this method is called it will receive both a reference to the accelerometer and the acceleration readings. &lt;br /&gt;
According to Apple documentation the following are recommended update frequency bands:&lt;br /&gt;
&lt;br /&gt;
&lt;table border="1"&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
Frequency (Hz)&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
Usage&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
10-20&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
Getting current orientation of device&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
30-60&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
Games and other real-time input applications&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;br /&gt;
70-100&lt;/td&gt;  &lt;td&gt;&lt;br /&gt;
For detecting high frequency motion such as the user hitting the device or shaking it quickly.&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;If you only need to know the general orientation of the device and  don’t need the accelerometer data then you should retrieve the  orientation of the device from the &lt;code&gt;UIDevice&lt;/code&gt; class.&amp;nbsp; To retrieve the device’s orientation you must first call the &lt;code&gt;UIDevice&lt;/code&gt;’s &lt;code&gt;beginGeneratingDeviceOrientationNotifications&lt;/code&gt;. Once this is called you can either read the current orientation from the orientation property. You can also subscribe to &lt;code&gt;UIDeviceOrientationDidChangeNotification&lt;/code&gt;. In either case if your application nolonger needs orientation events it should call &lt;code&gt;endGeneratingDeviceOrientationNotifications&lt;/code&gt;&amp;nbsp; to turn off the accelerometer and conserve power. &lt;br /&gt;
For a demonstration I'm building a program that will read the values from the accelerometer and display them on the screen&lt;br /&gt;
&lt;img src="http://www.codeproject.com/KB/iPhone/iOSGetStarted00/AccelDemo.PNG" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#import &lt;uikit&gt;
 
@interface AccelerometerDemonstrationViewController : UIViewController {
    IBOutlet    UITextField*    AccelX;
    IBOutlet    UITextField* AccelY;
    IBOutlet    UITextField* AccelZ;
    UIAccelerometer *myAccelerometer;
}
 
@property    (retain)    IBOutlet    UITextField    *AccelX;
@property    (retain)    IBOutlet    UITextField    *AccelY;
@property    (retain)    IBOutlet    UITextField    *AccelZ;
 
-(IBAction)startAccelerometerClicked:(id)sender;
-(IBAction)stopAccelerometerClicked:(id)sender;
 
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
 
@end&lt;/uikit&gt;&lt;/pre&gt;&lt;i&gt;&lt;b&gt;The class interface declaration for the accelerometer example&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#import "AccelerometerDemonstrationViewController.h"
 
 
@implementation AccelerometerDemonstrationViewController
@synthesize AccelX;
@synthesize AccelY;
@synthesize AccelZ;
 
 
-(IBAction)startAccelerometerClicked:(id)sender {
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.20] ;
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];
    
}
 
-(IBAction)stopAccelerometerClicked:(id)sender {
    [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
}
 
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    [AccelX.text release];
    [AccelY.text release];
    [AccelZ.text release];

    AccelX.text = [NSString stringWithFormat:@"%f", acceleration.x];
    AccelY.text = [NSString stringWithFormat:@"%f", acceleration.y];
    AccelZ.text = [NSString stringWithFormat:@"%f", acceleration.z];
}    
 
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
    self.AccelX = nul;
    self.AccelY = nul;
    self.AccelZ = nul;
}
 
 
- (void)dealloc {
    [AccelX dealloc];
    [AccelY dealloc];
    [AllocZ dealloc]
    [super dealloc];
}
 
@end&lt;/pre&gt;&lt;i&gt;&lt;b&gt;The implementation for the Accelerometer example.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
I could have a complete discussion alone covering math equations and  algorithms that are helpful when dealing with the accelerometer. For now  I'll just mention two that I've found helpful when working with an  accelerometer in previous programs.  The first equation is to get the magnitude of the accelerometer value.  For a device that's not moving this number should be close to one  (though the number may float around to be slightly greater than one of  slightly less than one depending one because of the accelerometer not  being 100% precise). For a number accelerating quickly it will be  greater than one. For a device in free fall it will be close to zero.  You can get the magnitude of the accelerometer reading by getting the  square root of &lt;code&gt;(x*x+y*y+z*z)&lt;/code&gt;. The other equation worth  knowing is getting the direction (in radians) in which the device is  tilting along some plane. For example, if I had a device laying flat on a  table and then decided to tilt it the direction in which the device is  tilted can be calculated with &lt;code&gt;atan2(y,x)&lt;/code&gt;.&amp;nbsp; &lt;i&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-5669745103354157768?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/M0FvN_wqbqA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/5669745103354157768/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/getting-started-with-iphone-and-ios.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/5669745103354157768?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/5669745103354157768?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/M0FvN_wqbqA/getting-started-with-iphone-and-ios.html" title="Getting Started with iPhone and iOS Development" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/getting-started-with-iphone-and-ios.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUHQXg8fip7ImA9Wx5WFUo.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-6487652135408998586</id><published>2010-09-27T01:19:00.000-07:00</published><updated>2010-09-27T02:03:50.676-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T02:03:50.676-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JQuery" /><title>Web App Common Tasks by jQuery</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;img src="http://www.codeproject.com/KB/applications/WebAppCommonTasksByjQuery/webappcommontasks.demo.png" /&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
One of my experience of using jQuery  is that I often need to search around for solutions to some particular tasks, although there are good chances that the problems you try to tackle have already been solved by someone else via a plug-in, you still need to digest, evaluate, test and sometimes modify it to fit your project needs. That's perfectly fine for most rapid web development efforts. However, for some browser based, low-level tasks that are common for almost all web applications, searching for multiple plug-ins then put them together and test them out would cost unnecessary time. This article provides a jQuery plug-in (CBEXP) that encapsulates the most common tasks together and is reusable for different web applications.&lt;br /&gt;
&lt;br /&gt;
For example, if your web application needs to conditionally (say, one Ajax call hasn't returned yet) warn user when navigating away or closing the browser window, or your client/service interaction relies on cookies and you want to make sure browser cookie is not turned off, or you need to parse query string and retrieve a particular parameter value in the client, or need to load different stylesheet dynamically without a post back to server, etc., it would be nice to have one jQuery plug in to handle all these low level browser based tasks, then we can focus more on application specific features.&lt;br /&gt;
&lt;br /&gt;
As a matter of fact, CBEXP plug-in was initially put together for a real world consumer facing web application, it has been tested and working, wish it would be useful for your web application too. &lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Dependencies&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
This plug in depends on jQuery 1.4.2, Cookie Plug-in and jQuery-JSON plug in, it's designed to be used without a server page (ASP, JSP, PHP, Ruby on Rails, etc.). It certainly can be used with a server page, I just want to point out it works fine with a static HTML file. I usually put it into a public facing landing page, if any browser setting goes unexpectedly, we can tell the user when page loads.&lt;br /&gt;
&lt;br /&gt;
The companion source code has a cbexp_demo.html page is a static HTML page, it shows examples on how the common tasks are performed.&lt;br /&gt;
&lt;br /&gt;
Since all the common tasks will be performed by JavaScript code, the first thing to check would be to make sure browser's JavaScript is enabled, if not, we're going to tell the user it's required and show steps to enable it.&lt;br /&gt;
&lt;br /&gt;
With the cbexp_demo.html page, HTML &amp;lt;noscript&amp;gt; tag is used to show alternative content when end user's browser has JavaScript disabled. The demo page has all the page content wrapped by a "pageContainer" (id) DIV, initially, the page CSS (stylesheets/cbexp.demo.css) hide the pageContainer DIV. If JavaScript is not enabled, all user sees are the content within &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;noscript&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; tag; If the JavaScript is already enabled, the documentReady event handler in cbexp.demo.js will show the pageContainer, see Fig.1 for details.&amp;lt;/noscript&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;// Fig.1. document ready event handler will not executived if JavaScript is disabled, otherwise it would fade in the page content 

$(function () { $('#pageContainer').fadeIn(); });
&lt;/pre&gt;Now that we resolved dependencies, let's move onto our first common task by jQuery cbexp plugin.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Check Cookie is enabled&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Similarly, we would tell user Cookie needs to be enabled when it's turned off. All these HTML content for no-cookie case is wrapped within a DIV with ID of "noCookieContainer", just like pageContainer, it's initially is set hidden by stylesheets/cbexp.demo.css:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre1" lang="css"&gt;// Fig. 2. Page CSS sets both pageContainer and noCookieContainer hidden  #pageContainer, #noCookieContainer {   display:none;  }&lt;/pre&gt;&lt;br /&gt;
Within the documentReady event handler, it invokes the client side cookie detection method, when it's not enabled, it would show noCookie content. When your web application requires both JavaScript and Cookie, the document ready event handler would become:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre2" lang="jscript"&gt;//Fig.3 When both JavaScript and Cookie are required, document ready handles the detection and show/hide appropriate content  $(function ()  {   if ($.cbexp.isCookieEnabled())    $('#pageContainer').fadeIn();   else    $('#noCookieContainer').fadeIn();  });&lt;/pre&gt;&lt;br /&gt;
Notice the call to $.cbexp.isCookieEnabled(), it's implemented in CBEXP plug in as a client side cookie detection, it simply tries to write a cookie, if it can read it back, then browser cookie settings is good to go. With the help from jQuery Cookie Plug-in, here is the code for isCookieEnabled:&lt;br /&gt;
&lt;br /&gt;
&lt;pre id="pre3" lang="jscript"&gt;//Fig.4 Client side cookie detector, writes/reads then remove the detector cookie  isCookieEnabled: function ()  {      $.cookie('cbexp_cookie_detector', 'cbexp_test');      var retVal = ('cbexp_test' == $.cookie('cbexp_cookie_detector'));        $.cookie('cbexp_cookie_detector', null);        return retVal;  }&lt;/pre&gt;&lt;br /&gt;
Certainly, there are many other ways to detect cookie setting, like a round trip to server, but I found this client side approach is easy and quick. If your web application doesn't require cookie, you can then use the CBEXP plugin without the dependency on the jQuery Cookie Plug in.&lt;br /&gt;
&lt;br /&gt;
Beside cookie setting detection, query string parsing is another common task.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Parse Query Strings&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
CBEXP Plug in has a simple and efficient method to parse out all query string based on current page's URL, in the case of no query string is defined, it returns empty array object. Here is the code: &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;//Fig. 5 Basic query string pasrsing method with in cbexp plugin
getQueryString: function ()
{
    var qs = window.location.search;
    if (qs.length &amp;lt;= 1)
        return new Array();
    qs = qs.substring(1, qs.length);
    var a = qs.split("&amp;amp;");
    var b = new Array();
    for (var i = 0; i &amp;lt; a.length; ++i)
    {
        var p = a[i].split('=');
        b[p[0]] = decodeURIComponent(p[1]);
    }
    return b;
}
&lt;/pre&gt;&lt;br /&gt;
A specific query string parameter value can be retrieved by querying the return value of getQueryString, like: $.cbexp.getQueryString()[QueryStringParamName], if the value is defined, it would return a string decoded from URI-encoded string, if not defined, it would null.&lt;br /&gt;
&lt;br /&gt;
Later in this article, I'll show an example to dynamically load CSS and HTML base on different query string parameter values.&lt;br /&gt;
&lt;br /&gt;
What above is about browser information detectyion and information retrieval tasks, let's turn our attention to client-service interactions. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Extend Ajax call with X-HTTP-Method-Override&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
In our web application, we deliberately desinged our secure RESTful-like web services API to be POST-only or overloaded POST style, when client initiates a service call, it only uses one HTTP verb ---- POST. The main reason is that our web application is targetting regular consumer, each end user may have different firewall settings, some firewalls do not allow PUT or DELETE at all, only GET and POST are OK to go through port 80. Since we still to protect GET requests in our secure web service, so all requests essetially become a POST request.&lt;br /&gt;
&lt;br /&gt;
We gain some consistency in service request side in terms of request body for authentication and authorization information, but we sort of lost some standard operation meanings for HTTP verbs, like the regaulr meaning for GET (read), PUT (create) and DELETE. To solve this service request verb-meaningless-issue and also try to leverage some server side framework's support for HTTP verb (to map certain HTTP verb to corresponding CRUD method in service layer), we extend jQuery ajax API to optionally set X-HTTP-Method-Override HTTP header, similar to what Google Data Protocal does.&lt;br /&gt;
&lt;br /&gt;
The idea is: all service requests will go through a common Ajax wrapper method in CBEXP plugin, by optionally passing in the GET, PUT and DELETE verbs, the method will package the correct headers and settings for the Ajax call, here are the details: &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;Fig. 6. Ajax call wraper for overloaded POST method with X-HTTP-Method-Override support    
postJson: function (postURL, jsDataObj, onSuccess, onError, httpMethodOverride)
{
    var beforeSendCallback = null;

    try
    {
        if (httpMethodOverride != undefined)
        {
            httpMethodOverride = httpMethodOverride.toUpperCase();
            if (httpMethodOverride == "GET" || httpMethodOverride == "PUT" || httpMethodOverride == "DELETE")
            {
                beforeSendCallback = function (xhr)
                {
                    xhr.setRequestHeader("X-HTTP-Method-Override", httpMethodOverride);
                    xhr.withCredentials = true;
                };
            }
        }
        else
        {
            beforeSendCallback = function (xhr)
            {
                xhr.withCredentials = true
            };
        }

        $.ajax({
            type: "POST",
            beforeSend: beforeSendCallback,
            contentType: "application/json",
            dataType: "json",
            url: postURL,
            data: $.toJSON(jsDataObj),
            async: true,
            success: onSuccess,
            error: onError
        });
    }
    catch (err)
    {
        alert("Ajax call error : " + err.description);
    }
}
&lt;/pre&gt;Notice it utilizes $.toJSON(jsDataObj) from jQuery JSON plugin to serialize a JavaScript object to JSON string as the POST body.&lt;br /&gt;
&lt;br /&gt;
What above is our extension to Ajax call. In a broader meaning of "Ajax", it not only means interacting with services via XMLHTTPRequest, but also includes dynamically and conditionally loading HTML , Javascript and CSS files to the DOM solely based on client side logic, let's how EBEXP plugin support this as a common task. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Dynamically loading HTML, JavaScript and CSS from client&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
jQuery is a lightweight while powerful JavaScript library, I was amazed to find out it already had built-in support for dynamically loading HTML by jQuery .load API, and also has a .getScript API  for dynamically loading JavaScript file, it definitely enables varies techniques and treatments in terms of building a dynamic web page from client. In the case the client needs to load CSS file at runtime, CBEXP plugin provides a simple easy to use method:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;Fig. 7 Support for programmatically loading CSS
loadPageCSS: function (cssUrl)
{
    $('&amp;lt;link&amp;gt;&amp;lt;/link&amp;gt;').appendTo('head').attr({
        rel: "stylesheet",
        type: "text/css",
        href: cssUrl
    });
}
&lt;/pre&gt;&lt;br /&gt;
The method simply creates a new &amp;lt;link&amp;gt;&amp;lt;/link&amp;gt; tag with proper attributes and append it to page's header. According to the general cascading rules of CSS, the lately loaded CSS will win over previously loaded external CS rules if they have any conflicts.&lt;br /&gt;
&lt;br /&gt;
Although the code looks short and simple, when putting all the pieces together, it really enables some powerful features, like to let client make sure browser has the right settings, to dynamically change page's layout and look and feel (by programmatically loading CSS) based on parameters (by parsing query strings).&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;b&gt;Warn the user before they leave&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
In some use cases, when user tries to leave, either by clicking a link, typing a new URL in browser's address bar, clicking on browser windows's close button, we want to warn the user if they leave some data will be lost. CBEXP plugin supports a programmatic way to enable or disable the warning message. From application perspective, when set the dirty flag, it's anbled, otherwise it would disable. Here below are the code in CBEXP:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;setDirtyFlag: function (docDirty)
{
    $.cbexp.isDirty = docDirty;
    if (docDirty)
        $(window).bind('beforeunload', $.cbexp.confirmExit);
    else
        $(window).unbind('beforeunload', $.cbexp.confirmExit);
},

getDirtyFlag: function ()
{
    return $.cbexp.isDirty;
},

confirmExit: function ()
{
    if ($.cbexp.isDirty)
        return "Exiting this page will end your session. If you haven't saved your info, it could be lost.";
},
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-6487652135408998586?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/biJ1GVXvdSE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/6487652135408998586/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/web-app-common-tasks-by-jquery.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6487652135408998586?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6487652135408998586?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/biJ1GVXvdSE/web-app-common-tasks-by-jquery.html" title="Web App Common Tasks by jQuery" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/web-app-common-tasks-by-jquery.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMBQHs-cCp7ImA9Wx5WFUo.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-6754539161757204236</id><published>2010-09-27T01:00:00.000-07:00</published><updated>2010-09-27T01:00:51.558-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-27T01:00:51.558-07:00</app:edited><title>Scroll Bar for Blog Post Body</title><content type="html">Adding Scrollbar to Blog Post body&lt;br /&gt;
once you are logged into Blogger account, go to Template -&amp;gt; Edit HTML and scroll to this code. Add the portion shown in red:-&lt;br /&gt;
&lt;br /&gt;
Step 1 : Open your Blogger Account and Edit Html Under Layouts Tab;&lt;br /&gt;
Set 2 : Search for .post ( by browser Search) and Put the Red Portion in Curly Bracket. { }&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;.post {
height:200px;
overflow:auto;

}&lt;/pre&gt;&lt;br /&gt;
This will give you scrollbars to every post:-&lt;br /&gt;
&lt;br /&gt;
Scrollbars within Blog Post&lt;br /&gt;
Sometimes, you may not want to have the scrollbars to all the [...]&lt;br /&gt;
&lt;br /&gt;
This will give you scrollbars to every post:- &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Scrollbars within Blog Post&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: center;"&gt;&lt;img src="http://lh5.ggpht.com/_SfQ1e4Wjs8M/SZ47Msg4rLI/AAAAAAAAAGs/h_-hjn_-Vts/scrollbarpost_thumb%5B1%5D.jpg?imgmax=800" /&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;This setting, scrollbars will automatically appear according to your need:-&lt;/b&gt;&lt;br /&gt;
Sometimes, you may not want to have the scrollbars to all the blog posts, but only for several paragraphs within a post. Assuming you are writing an article and you wish to enclose some long text within a scrollbox, you have to first define a class within the stylesheet.&lt;br /&gt;
&lt;br /&gt;
For example, we can insert in the stylesheet this code to specify the maximum height and width of the scrollbox. Once the text overflows&lt;br /&gt;
&lt;br /&gt;
Step 1 : Open your Blogger Account and Edit Html Under Layouts Tab;&lt;br /&gt;
Set 2 : Search for  by Browser search place the below code before it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;.scrollbox {

height:100px;

width:400px;

overflow:auto;

}&lt;/pre&gt;Step 3: Save the template.&lt;br /&gt;
&lt;br /&gt;
Next, when you are writing a post, switch from the “Compose” mode to the “Edit HTML” mode and put the below code where your want to appear scrolling bar.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;&lt;img src="http://lh5.ggpht.com/_SfQ1e4Wjs8M/SZ47Ord4aiI/AAAAAAAAAG0/P-7-ywmWGg0/scrollbarpost1_thumb%5B2%5D.jpg?imgmax=800" /&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre&gt;&amp;lt;div class=”scrollbox”&amp;gt;TEXT TO BE INCLUDED IN THE SCROLLBOX.&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;br /&gt;
You can continue typing the post by switching back to the “Compose” mode.&lt;br /&gt;
&lt;br /&gt;
After you are done, when you publish your post, you will see that only the part of the text comprised with the tags will be in a scrollbox, like this:-&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-6754539161757204236?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/IOSIpcONayc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/6754539161757204236/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/scroll-bar-for-blog-post-body_27.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6754539161757204236?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/6754539161757204236?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/IOSIpcONayc/scroll-bar-for-blog-post-body_27.html" title="Scroll Bar for Blog Post Body" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_SfQ1e4Wjs8M/SZ47Msg4rLI/AAAAAAAAAGs/h_-hjn_-Vts/s72-c/scrollbarpost_thumb%5B1%5D.jpg?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/scroll-bar-for-blog-post-body_27.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMEQ3c5fSp7ImA9Wx5WEkk.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-5486117612942277173</id><published>2010-09-23T04:46:00.000-07:00</published><updated>2010-09-23T04:46:42.925-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-23T04:46:42.925-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Blogger Hack" /><title>Show Limited Number of Labels in Widget.</title><content type="html">As you write more and more posts you will keep adding labels to them to categorize your posts. You can add more than one label to any single post. Labels are useful as they serve as keywords channelling traffic to your posts through search engines like Technorati.&lt;br /&gt;
&lt;br /&gt;
However the list of labels in your blog can get to be very long stretching your sidebar until y&lt;br /&gt;
&lt;br /&gt;
our blog post looks like a flag on top of a long sidebar. To prevent this you can modify the code of your Labels widget to show only the topmost labels in your blog.............. &lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;LIMIT LABEL NUMBER&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
To limit the number of labels shown in your Labels sidebar widget login at Blogger.com and click 'Layout' link on Dashboard. The Page Elements subtab of Template tab will open. If you do not have a Labels widget in the sidebar Add a Labels Page Element to it.&lt;br /&gt;
&lt;br /&gt;
After the Labels widget is added click on Edit Html subtab of Template tab. This will open the Template code box on the Edit Html subtab. Click the Expand Widgets Template checkbox on top of the Template code box to put a check mark in it. The Template code box will show the expanded widgets templates.&lt;br /&gt;
&lt;br /&gt;
Scroll down in the Template code box to locate the code for the Labels widget. This will look like this : &lt;br /&gt;
&lt;pre&gt;&amp;lt;b:widget id='Label1' locked='false' title='Labels' type='Label'&amp;gt;

  &amp;lt;b:includable id='main'&amp;gt;
&amp;lt;b:if cond='data:title'&amp;gt;

  &amp;lt;h2&amp;gt;&amp;lt;data:title/&amp;gt;&amp;lt;/h2&amp;gt;

  &amp;lt;/b:if&amp;gt;

  &amp;lt;div class='widget-content'&amp;gt;

  &amp;lt;ul&amp;gt;

  &amp;lt;b:loop values='data:labels' var='label'&amp;gt;

  &amp;lt;li&amp;gt;

  &amp;lt;b:if cond='data:blog.url == data:label.url'&amp;gt;

  &amp;lt;span expr:dir='data:blog.languageDirection'&amp;gt;

  &amp;lt;data:label.name/&amp;gt;

  &amp;lt;/span&amp;gt;

  &amp;lt;b:else/&amp;gt;

  &amp;lt;a expr:dir='data:blog.languageDirection' expr:href='data:label.url'&amp;gt;

  &amp;lt;data:label.name/&amp;gt;

  &amp;lt;/a&amp;gt;

  &amp;lt;/b:if&amp;gt;

  &amp;lt;span dir='ltr'&amp;gt;(&amp;lt;data:label.count/&amp;gt;)&amp;lt;/span&amp;gt;

  &amp;lt;/li&amp;gt;

  &amp;lt;/b:loop&amp;gt;

  &amp;lt;/ul&amp;gt;
&amp;lt;b:include name='quickedit'/&amp;gt;

  &amp;lt;/div&amp;gt;

  &amp;lt;/b:includable&amp;gt;

  &amp;lt;/b:widget&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
REPLACE THE WHOLE ABOVE CODE WITH THE CODE BELOW : &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;b:widget id='Label1' locked='false' title='Labels' type='Label'&amp;gt;

&amp;lt;b:includable id='main'&amp;gt; 

&amp;lt;b:if cond='data:title'&amp;gt;

&amp;lt;h2&amp;gt;&amp;lt;data:title/&amp;gt;&amp;lt;/h2&amp;gt;

&amp;lt;/b:if&amp;gt;

&amp;lt;ul&amp;gt;

&amp;lt;script type='text/javascript'&amp;gt;

var labelnum = 0;

&amp;lt;b:loop values='data:labels' var='label'&amp;gt;

if (&amp;lt;data:label.count/&amp;gt; &amp;amp;gt; 2) {

document.write(&amp;amp;quot;&amp;lt;li&amp;gt;&amp;lt;a expr:href='data:label.url +  "?max-results=100"' 

rel='nofollow'&amp;gt;&amp;lt;span&amp;gt;&amp;lt;data:label.name/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;(&amp;lt;data:label.count/&amp;gt;)&amp;lt;/li&amp;gt;&amp;amp;quot;);

}

&amp;lt;/b:loop&amp;gt;

&amp;lt;/script&amp;gt;

&amp;lt;/ul&amp;gt;

&amp;lt;b:include name='quickedit'/&amp;gt;

&amp;lt;/b:includable&amp;gt;

&amp;lt;/b:widget&amp;gt;&lt;/pre&gt;&lt;br /&gt;
The code above will only show labels with more than two posts. To increase number of labels increase the number two in this code : &lt;br /&gt;
&lt;pre&gt;if (&amp;lt;data:label.count/&amp;gt; &amp;amp;gt; 2) {&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-5486117612942277173?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/NVsNUz9Uk-M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/5486117612942277173/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/show-limited-number-of-labels-in-widget.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/5486117612942277173?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/5486117612942277173?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/NVsNUz9Uk-M/show-limited-number-of-labels-in-widget.html" title="Show Limited Number of Labels in Widget." /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/show-limited-number-of-labels-in-widget.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ABR3oyeCp7ImA9Wx5WEkk.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-2247765813193700594</id><published>2010-09-23T04:35:00.000-07:00</published><updated>2010-09-23T04:35:56.490-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-23T04:35:56.490-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Blogger Hack" /><title>Javascript Redirect Traffic from Blogspot to WordPress Site</title><content type="html">Ok. So you’ve had a blogspot blog for a little while and you’ve decided you want a WordPress site. How do you redirect traffic from the old site to the new site and lose as little traffic as possible in the process.&lt;br /&gt;
&lt;br /&gt;
First.  Use the import feature available in WordPress.  From your Daskboard, look for Tools &gt; Import&lt;br /&gt;
&lt;br /&gt;
Second.  Add some javascript code to your blogger template. Update the vars blogTitle and wordPressUrl to match your blogspot blog.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;p&gt;&amp;lt;script&amp;gt;&lt;br&gt;
  var blogTitle = 'Flexing My Kerkness';&lt;br&gt;
  var wordPressUrl = 'http://kerkness.ca';&lt;/p&gt;&lt;p&gt;if( document.title == blogTitle ){&lt;br&gt;
  window.location = wordPressUrl;&lt;br&gt;
  } else {&lt;br&gt;
  var newUrl = str_replace( document.title, blogTitle+&amp;rsquo;: &amp;lsquo;, &amp;rdquo; );&lt;br&gt;
  window.location = wordPressUrl + &amp;lsquo;/?s=&amp;rsquo; + newUrl;&lt;br&gt;
  }&lt;br&gt;
  function str_replace(haystack, needle, replacement) {&lt;br&gt;
  var temp = haystack.split(needle);&lt;br&gt;
  return temp.join(replacement);&lt;br&gt;
  }&lt;br&gt;
  &amp;lt;/script&amp;gt;&lt;/p&gt;&lt;/pre&gt;&lt;br /&gt;
Basically what this script does is redirects from your blogger site to your new domain while conducting a search based on the title of page being requested.&lt;br /&gt;
&lt;br /&gt;
For example. If you had a post called “How to change outboard motor oil” on blogger. When you try and access the blogspot url for that post you will be directed to the new wordpress domain and you will search for posts matching “How to change outboard motor oil”. If that post was imported into word press and you haven’t changed the title. Users will be shown a link to the post on your new site. Also they may find any new or relevant content you’ve posted since making the change to WordPress.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-2247765813193700594?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/fhSr6qdRD9Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/2247765813193700594/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/javascript-redirect-traffic-from.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/2247765813193700594?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/2247765813193700594?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/fhSr6qdRD9Q/javascript-redirect-traffic-from.html" title="Javascript Redirect Traffic from Blogspot to WordPress Site" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/javascript-redirect-traffic-from.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EGRHw5eCp7ImA9Wx5WEkk.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-4950765643338529092</id><published>2010-09-23T04:33:00.000-07:00</published><updated>2010-09-23T04:33:45.220-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-23T04:33:45.220-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Blogger Hack" /><title>JAX Labels Reloaded</title><content type="html">The AJAX Labels is back with more features! I was planning to release this with my new template, but the template design is slipping beyond schedule.&lt;br /&gt;
Note: If you want to integrate AJAX Labels with Phydeaux3's Label Clouds, read this post and come back here.&lt;br /&gt;
Some of the new features are: &lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Built-in navigation system.&lt;/li&gt;
&lt;li&gt;More user customizability. (You don't even need to know coding for that!)&lt;/li&gt;
&lt;li&gt;Support for Unicode Categories in IE.&lt;/li&gt;
&lt;li&gt;More user-friendly installation. (Code to be copied/modified in template is reduced)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
The installation of this hack afresh would be easy. But upgrading from my previous version is a bit knotty. Anyway, I will explain both. If you get stuck, feel free to comment and I'll be there to help. FRESH INSTALLATION Click here for Up gradation instructions. If you already have AJAX Labels installed, you can directly jump to up gradation instructions. Like the first version, this one too needs the Prototype JS framework. You can either store it in a location of your preference, or use the location that I've given below. First of all, back up your template. It is always a good idea to back up your template, so that you can revert if you mess things up. 1. Click Page Layout-&amp;gt;Edit HTML. Check the box saying "Expand Widget Templates" Look for the &amp;lt;/head&amp;gt; tag in your template. Insert the following code just above that.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;style type='text/css'&amp;gt; 

#indicator {position:fixed;z-index:1000;padding:15px   0;top:40%;background-color:#FFFFFF;border:1px solid   #AAAAAA;width:176px;left:50%;margin-left:-88px;text-align:center;} 

#search-result {border:1px solid #AAAAAA;padding:10px;padding-bottom:30px;font-size:85%;} 

.search-result-meta {background:#EFEFEF;padding:2px;} 

.search-result-meta img {border-width:0;vertical-align:text-bottom;} 

.search-title {font-size:1em;padding-bottom:3px;font-weight:bold;text-align:left;text-decoration:underline;} 

.search-cat   {display:block;padding:3px;font-size:1em;margin-top:5px;margin-bottom:5px;border-bottom:1px   solid #C0C0C0;font-weight:bold;} 

.search-close {color:silver;float:right;border:1px solid #F5F5F5;margin-top:10px;cursor:pointer;} 

.search-result-nav {font-size:1.4em;font-weight:bold;padding:5px 0pt;text-align:center;} 

&amp;lt;/style&amp;gt; 

&amp;lt;script type='text/javascript' src='http://bloggerhacked.googlepages.com/prototype.js' /&amp;gt; 

&amp;lt;script type='text/javascript'&amp;gt; 

//&amp;lt;![CDATA[ 

// User customisable parameters 

// ---------------------------- 

// maxresults - Number of results to show per page 

// navFlag - Set Navigation ON or OFF. Give 1 for ON and 0 for OFF. 

// feedLabel - Text to show for the label feed link. 

// catLabel - Label for categories. 

// closeLabel - Label for Close button. You can use hypertext also. 

var maxresults = 5; 

var navFlag = 1; //ON by default 

var feedLabel = "Subscribe to"; 

var catLabel = "Sorted into:"; 

var closeLabel = "Click to close"; 

//]]&amp;gt; 

&amp;lt;/script&amp;gt; 

&amp;lt;script type='text/javascript' src='http://bloggerhacked.googlepages.com/ajaxlabels.js' /&amp;gt;&lt;/pre&gt;&lt;br /&gt;
Note: You can avoid the prototype script addition line if you already have added the prototype.js script to your template (It is quite likely, if you have added some hack to your blog). If you don't understand what I'm saying, never mind. Now the customization part. See the snippets in red above. Those are the stuff which you can customise. Just above that I have written comments on what each represent. To customize them, you just need to modify them to the appropriate value. For example, if you want to change the close button text from "Click to close" to, say, "[X]", then simply change "Click to close" in the red area to "[X]". Navigation Feature: The navigation feature allows pagination of the results. So you can view all the results in several pages. maxresults and navFlag  together determine how it is shown. navFlag is the parameter saying whether you want this feature or not. The number of results shown per page will be decided by maxresults. The number of pages will be calculated automatically. Eg: Lets say, you have 13 posts with a particular label in your blog. Case 1: maxresults=5 and navFlag=1  You will have 3 pages (peekaboo blocks) with 5 results each. There will be a navbar which will let you go to any of those 3 pages. Case 2: maxresults=5 and navFlag=0  You will have a single page with 5 recently updated posts with the particular label. You won't be able to view other results Case 3: maxresults=20 and navFlag=1  You will have a single page with 13 results (Because 13 is less than 20). If you know CSS, you can modify the look of your result block as well. 2. Locate the following code in your template:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;b:loop values='data:post.labels' var='label'&amp;gt; 

&amp;lt;a expr:href='data:label.url' rel='tag'&amp;gt;&amp;lt;data:label.name/&amp;gt;&amp;lt;/a&amp;gt;&lt;/pre&gt;Replace it with this:&lt;br /&gt;
&lt;pre&gt;&amp;lt;b:loop values='data:post.labels' var='label'&amp;gt; 



&amp;lt;a href='#sres' expr:onclick='"javascript:getCat(\"" +   data:label.name + "\",null)"'   rel='tag'&amp;gt;&amp;lt;data:label.name/&amp;gt;&amp;lt;/a&amp;gt;&lt;/pre&gt;&lt;br /&gt;
3. Optional:If you have the labels widget in your template.&lt;br /&gt;
&lt;br /&gt;
Locate the following code in your template:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;lt;b:if cond='data:blog.url == data:label.url'&amp;gt;

  &amp;lt;data:label.name/&amp;gt;

  &amp;lt;b:else/&amp;gt;

  &amp;lt;a href='data:label.url'&amp;gt;&amp;lt;data:label.name/&amp;gt;&amp;lt;/a&amp;gt;

  &amp;lt;/b:if&amp;gt;



Replace it with this:
&amp;lt;b:if cond='data:blog.url == data:label.url'&amp;gt;

  &amp;lt;data:label.name/&amp;gt;

  &amp;lt;b:else/&amp;gt;

  &amp;lt;a href='#sres' expr:onclick='"javascript:getCat

(\"" + data:label.name + "\",null)"' &amp;gt;&amp;lt;data:label.name/&amp;gt;&amp;lt;/a&amp;gt;

  &amp;lt;/b:if&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
4. Click on the button below.&lt;br /&gt;
&lt;br /&gt;
&lt;form action="http://beta.blogger.com/add-widget" method="post"&gt;&lt;span id="fullpost"&gt;&lt;span id="fullpost"&gt;&lt;input name="widget.title" type="hidden" /&gt;&lt;textarea name="widget.content" style="display: none;"&gt;&amp;lt;div id="indicator" style="display:none"&amp;gt;&amp;lt;img alt="Indicator" src="http://bloggerhacked.googlepages.com/indicator.gif" /&amp;gt; Loading...&amp;lt;/div&amp;gt;&amp;lt;div id="search-result" style="display:none"&amp;gt;&amp;lt;a name="sres"&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;div class="search-close" onclick="javascript:Element.hide('search-result')"&amp;gt;&amp;lt;span id="preserve28e29bc50e8543bdbc285c3b47ad246c" class="wlWriterPreserve"&amp;gt;&amp;lt;script type="text/javascript"&amp;gt;document.write(closeLabel);&amp;lt;/script&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div id="show-result"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class="search-close" onclick="javascript:Element.hide('search-result')"&amp;gt;&amp;lt;span id="preservee463285a218e49dfabc9efcfc5e8ae87" class="wlWriterPreserve"&amp;gt;&amp;lt;script type="text/javascript"&amp;gt;document.write(closeLabel);&amp;lt;/script&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;/textarea&gt;&lt;input name="go" type="submit" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/form&gt;&amp;lt;div id="indicator" style="display:none"&amp;gt;&amp;lt;img alt="Indicator" src="http://bloggerhacked.googlepages.com/indicator.gif" /&amp;gt; Loading...&amp;lt;/div&amp;gt;&amp;lt;div id="search-result" style="display:none"&amp;gt;&amp;lt;a name="sres"&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;div class="search-close" onclick="javascript:Element.hide('search-result')"&amp;gt;&amp;lt;span id="preserve28e29bc50e8543bdbc285c3b47ad246c" class="wlWriterPreserve"&amp;gt;&amp;lt;script type="text/javascript"&amp;gt;document.write(closeLabel);&amp;lt;/script&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div id="show-result"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class="search-close" onclick="javascript:Element.hide('search-result')"&amp;gt;&amp;lt;span id="preservee463285a218e49dfabc9efcfc5e8ae87" class="wlWriterPreserve"&amp;gt;&amp;lt;script type="text/javascript"&amp;gt;document.write(closeLabel);&amp;lt;/script&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;This will take you to an Add Widget Screen. Select your blog and click on Add widget. 5. Save your template. That was a breeze, wasn't it? &lt;a href="http://draft.blogger.com/post-edit.g?blogID=3436146991888729493&amp;amp;postID=796326170093012362" name="upgrade"&gt;&lt;/a&gt;UPGRADATION Caution! If you are installing AJAX Labels for the first time, don't proceed any further. You are already finished with your installation. This section is only for upgrading from the previous version. 1. Back up your template first. (Be pessimistic in these matters ;) ) 2. Go to Edit HTML. Look for my previous installation of Javascript. It is very easy to find. It is enclosed within &lt;code&gt;&amp;lt;!-- Begin Categories --&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;!-- End Categories --&amp;gt;&lt;/code&gt; Delete that entire portion. 3. Now check &lt;a href="http://draft.blogger.com/post-edit.g?blogID=3436146991888729493&amp;amp;postID=796326170093012362#fresh1"&gt;Step 1&lt;/a&gt; of the FRESH INSTALLATION section. Follow that step and come back here. 4. Search for the following snippet in your template. &lt;code&gt;'"javascript:getCat(\"" + data:label.name + "\")"'&lt;/code&gt; There will be two places where this occurs. Replace both places with this &lt;code&gt;'"javascript:getCat(\"" + data:label.name + "\",null)"'&lt;/code&gt; 5. Save your template and go to page layout screen and delete the HTML/Javascript widget you had created when you installed the previous version. 6. Go to &lt;a href="http://draft.blogger.com/post-edit.g?blogID=3436146991888729493&amp;amp;postID=796326170093012362#fresh4"&gt;step 4&lt;/a&gt; of FRESH INSTALLATION section. Follow that step and come back here. 7. Save your template and you are done. There! That was not very difficult. ACKNOWLEDGEMENTS Tsung-Kai Chen - For his several comments and the bugs he found in the previous version. Bahram - For the heads up on the Unicode Category issue in IE. Update 1: The code had minor syntax errors (due to wrong copy paste)because of which the hack was not working. Problem is fixed now. Reinstalling the hack will make it work. Update 2: Drat! Another silly mistake. The Close button was not working. I've fixed this. Just delete the widget and add it again (&lt;a href="http://draft.blogger.com/post-edit.g?blogID=3436146991888729493&amp;amp;postID=796326170093012362#fresh4"&gt;Step 4&lt;/a&gt;) . You don't have to redo any other steps. Update 3: Arrgh!! Another bug. I have made the corrections. You will have to redo Steps 2, 3 and 4. This will remove support for the rel-tag microformat. I will release an update if I find a way to work around that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-4950765643338529092?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/Qf6SyrdoT-4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/4950765643338529092/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/jax-labels-reloaded.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/4950765643338529092?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/4950765643338529092?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/Qf6SyrdoT-4/jax-labels-reloaded.html" title="JAX Labels Reloaded" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/jax-labels-reloaded.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0cBQXo4eip7ImA9Wx5WEkk.&quot;"><id>tag:blogger.com,1999:blog-5489823151892664967.post-4364834247936526153</id><published>2010-09-23T04:24:00.000-07:00</published><updated>2010-09-23T04:24:10.432-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-23T04:24:10.432-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Blogger Hack" /><title>Adding Background Image to Post Titles</title><content type="html">&lt;img src="http://lh5.ggpht.com/_SfQ1e4Wjs8M/SZpjvwnnSsI/AAAAAAAAAGc/yhR1LOd8Ceo/Code_thumb%5B15%5D.jpg?imgmax=800" style="float: left; margin-right: 8px;" /&gt;&lt;br /&gt;
Dcloud Of Dcblog  brought this fantastic thing to us.By this we can put a Image Just behing the Post Title like on his blog.It’s Very Simple,the only thing is that you need to have a superb image to put on their.&lt;br /&gt;
&lt;br /&gt;
You will have to just check hard for the codes to implement as different blogger have different type of coding.&lt;br /&gt;
&lt;br /&gt;
To locate the code which controls the post titles go to your Layout Tab (located in your Customize window) and click the Edit HTML sub tab. The code you are searching for is “.post h6″ (it can be something else also,So try searching) which looks like this&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
Now to get the background image in there you have to add the code “background: url()” like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;.post h6
{
font-size:22px;
color:#000000;
font-weight:normal;
border-top:1px dotted #000000;
padding:4px 0 0 0;
width:599px;
no-repeat;
background: url(http://www.yourserver.com/yourimage.gif) no-repeat;
}&lt;/pre&gt;&lt;br /&gt;
Now Check your blog the image might be partially visible only so add the height attribute(equivalent to the height of the image).&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;.post h6
{
font-size:22px;
color:#000000;
font-weight:normal;
border-top:1px dotted #000000;
padding:4px 0 0 0;
width:599px;
no-repeat;
background: url(http://www.yourserver.com/yourimage.gif) no-repeat;
}
height: 80px;&lt;/pre&gt;&lt;br /&gt;
Now Checkout your blog,now you have to add/change the padding codes as you thinkl according to your blog to properly align the title within the image.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5489823151892664967-4364834247936526153?l=scriptstreasure.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ScriptBank/~4/n0XCxM3Fy6U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://scriptstreasure.blogspot.com/feeds/4364834247936526153/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://scriptstreasure.blogspot.com/2010/09/adding-background-image-to-post-titles.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/4364834247936526153?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5489823151892664967/posts/default/4364834247936526153?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ScriptBank/~3/n0XCxM3Fy6U/adding-background-image-to-post-titles.html" title="Adding Background Image to Post Titles" /><author><name>Asad</name><uri>http://www.blogger.com/profile/09579112810634963663</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="22" height="32" src="http://3.bp.blogspot.com/_T0w7K9AItgc/SYFzCA23ppI/AAAAAAAABso/kwj2JEx1Jn8/S220/Asad.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_SfQ1e4Wjs8M/SZpjvwnnSsI/AAAAAAAAAGc/yhR1LOd8Ceo/s72-c/Code_thumb%5B15%5D.jpg?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://scriptstreasure.blogspot.com/2010/09/adding-background-image-to-post-titles.html</feedburner:origLink></entry></feed>

