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

<channel>
	<title>Pini Dayan</title>
	<atom:link href="http://blogs.microsoft.co.il/pini_dayan/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.microsoft.co.il/pini_dayan</link>
	<description>The best thing about a boolean is even if you are wrong, you are only off by a bit.
</description>
	<lastBuildDate>Sun, 05 Jan 2014 18:04:57 +0000</lastBuildDate>
	<language>he-IL</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.2</generator>
	<item>
		<title>ExtJS 4–Managing dynamically loaded views with single controller</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2012/05/01/extjs-4managing-dynamically-loaded-views-with-single-controller/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2012/05/01/extjs-4managing-dynamically-loaded-views-with-single-controller/#comments</comments>
		<pubDate>Tue, 01 May 2012 14:15:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=1079738</guid>
		<description><![CDATA[Since lots of digging in the web had to be done in order to find answer to this I decided to write this down: When facing with the problem of dynamic loading of widgets we need to understand exactly how to load the view dynamically and how to associate them with their controller. Lots of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><P>Since lots of digging in the web had to be done in order to find answer to this I decided to write this down:</P><br />
<P>When facing with the problem of dynamic loading of widgets we need to understand exactly how to load the view dynamically and how to associate them with their controller. </P><br />
<P>Lots of questions should be answered in this scenario, for example:</P><br />
<P>1. Should there be an instance of the same type of controller many times for each of the views or should there be only one instance of the controller that manages all views?</P><br />
<P>2. Is there a single store or multiple stores for each view?</P><br />
<P>A quick sample will help to understand the problem: Let’s say we have a panel which displays list of employees. When clicking each employee we are showing the employee view in the middle. This view has some items like displaying the name of the employee and delete button, print button and so on. Since there can be only one instance of the same controller on the application controllers list we need a way to distinguish the view events. (Actually if we really want to we can create more than one controller instance but as we will see soon we don’t need to and this is not the way we want to go). </P><br />
<P>So here is the solution:</P><br />
<P>1. Create the view using Ext.create or Ext.widget.</P><br />
<P>2. Add it to some container panel.</P><br />
<P>3. Create a single instance of the controller or do nothing if it exists.</P><br />
<P>4. Make sure this controller listen to the events from the view and make sure each event from the view sends it reference to the controller.</P><br />
<P>5. When the controller needs to update something on that view or use one of its property access the view using the reference that the view send to him.</P><br />
<P><B>Here is the diagram for getting it to work:</B></P><br />
<P><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_75C6F1D9.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_75C6F1D9.png"><IMG style="BACKGROUND-IMAGE: none; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px; PADDING-TOP: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_524A4D74.png" width=630 height=408 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_524A4D74.png"></A></P><br />
<P><B></B></P><br />
<P>In regards for the store issue, it depends, If we need a single store for all our views or we need multiple stores for each view, both cases can be done.</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2012/05/01/extjs-4managing-dynamically-loaded-views-with-single-controller/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ExtJS 4– using config for creating automatic methods</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2012/04/24/extjs-4-using-config-for-creating-automatic-methods/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2012/04/24/extjs-4-using-config-for-creating-automatic-methods/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 13:31:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=1073800</guid>
		<description><![CDATA[Hi all, When you define a class using ExtJS you can specify a config section (just like you can add many cool things). By using the config you can create automatic methods that will be generated for you, for example: This will automatically create 8 methods for you. 4 methods for each property in the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><P>Hi all,</P><br />
<P>When you define a class using ExtJS you can specify a config section (just like you can add many cool things). By using the config you can create automatic methods that will be generated for you, for example:</P><br />
<P><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_7EABD3E8.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_7EABD3E8.png"><IMG style="BACKGROUND-IMAGE: none; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px; PADDING-TOP: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_3D31218F.png" width=290 height=184 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_3D31218F.png"></A></P><br />
<P>This will automatically create 8 methods for you. 4 methods for each property in the config section.</P><br />
<UL><br />
<LI><B>getXXXX</B> – returns the current value</LI><br />
<LI><B>setXXXX</B> – sets the property value to a new value </LI><br />
<LI><B>resetXXX</B> – reverts the property value to its default value </LI><br />
<LI><B>applyXXXX</B>– this is a template method that you can choose to define. It is called whenever setTitle is called.</LI></UL><br />
<P>This great thing happen due to a preprocessor that each ExtJS class has. Since each class you define is Ext.Class instance it has this preprocessor (config preprocessor).</P><br />
<P>Enjoy, Pini</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2012/04/24/extjs-4-using-config-for-creating-automatic-methods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ExtJS 4–Loading controllers dynamically</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2012/04/24/extjs-4loading-controllers-dynamically/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2012/04/24/extjs-4loading-controllers-dynamically/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 13:12:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[ExtJS]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=1073791</guid>
		<description><![CDATA[Hi all, Since I had to look it up really hard in the network I decided to write this important post in order to understand how to load a controller dynamically when using ExtJS 4.0.7 MVC. So here goes, Lets say&#160; you are building a web application using ExtJS MVC and you wish to load [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><P>Hi all, Since I had to look it up really hard in the network I decided to write this important post in order to understand how to load a controller dynamically when using ExtJS 4.0.7 MVC.</P><br />
<P>So here goes, Lets say&nbsp; you are building a web application using ExtJS MVC and you wish to load some views and their corresponding controllers dynamically. this can be used to load certain views for different user roles or simply to provide a “bag” of widgets that can be added if the user wishes to add them to its page/workspace/dashboard.</P><br />
<P>So lets suppose we have a view that displays the widgets we can add, each widget is represented using a button with the widgets name. when clicking this button the following things happen:</P><br />
<P>1. the controller who listens to this event will fire an application event.</P><br />
<P>2. Another controller responsible for the container of the dynamic widgets will listen to this event and handle this event.</P><br />
<P>3. This controller will perform 2 things:</P><br />
<BLOCKQUOTE><br />
<P>a. Add the view dynamically to the container:<A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_0FE6F751.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_0FE6F751.png"><IMG style="BACKGROUND-IMAGE: none; BORDER-RIGHT-WIDTH: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_155567F5.png" width=378 height=108 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_155567F5.png"></A></P></BLOCKQUOTE><br />
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b. Will create and add the controller for this view to the application controllers list:</P><br />
<BLOCKQUOTE><br />
<P><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_7F1F4CA2.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_7F1F4CA2.png"><IMG style="BACKGROUND-IMAGE: none; BORDER-RIGHT-WIDTH: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_570C9D83.png" width=337 height=40 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_570C9D83.png"></A></P></BLOCKQUOTE><br />
<P>4. The loadController function is available since I added it to the application instance like this:</P><br />
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_2AEFA092.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_2AEFA092.png"><IMG style="BACKGROUND-IMAGE: none; BORDER-RIGHT-WIDTH: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_111B6A63.png" width=517 height=265 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_111B6A63.png"></A></P><br />
<P>By using the this.getController method we are actually instantiating this controller and adding it to the list of controllers.</P><br />
<P>Here is the internal code for this method:</P><br />
<P>function(name) {</P><br />
<P>var controller = this.controllers.get(name);</P><br />
<P>if (!controller) {</P><br />
<P>controller = Ext.create(this.getModuleClassName(name, 'controller'), {</P><br />
<P>application: this,</P><br />
<P>id: name</P><br />
<P>});</P><br />
<P>this.controllers.add(controller);</P><br />
<P>}</P><br />
<P>return controller;</P><br />
<P>}</P><br />
<P>Hoe this helps, Pini</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2012/04/24/extjs-4loading-controllers-dynamically/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScript Callee property</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2012/01/29/javascript-callee-property/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2012/01/29/javascript-callee-property/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 08:25:20 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=1000927</guid>
		<description><![CDATA[Hi all, It always amazes me how I discover another JavaScript feature I wasn’t aware of. The feature I want to discuss here in this post is the Callee property we have from the arguments property we have when we are in a function scope. This property will return the current function being executed right [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Hi all,</p>
<p>It always amazes me how I discover another JavaScript feature I wasn’t aware of. The feature I want to discuss here in this post is the <a href="http://msdn.microsoft.com/en-us/library/334e1zza(v=vs.94).aspx">Callee</a> property we have from the arguments property we have when we are in a function scope.</p>
<p>This property will return the current function being executed right now. In addition we have the <a href="http://msdn.microsoft.com/en-us/library/7t96kt3h(v=vs.94).aspx">caller</a> property that we can use to get a reference to the calling function.Imagine you could even do crazy stuff like getting the caller function and its argument by doing something like:</p>
<p>arguments.callee.caller.arguments[0].</p>
<p>Here for example we are doing something nice:</p>
<p><a href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_71BE0AFA.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_2EFEBFC2.png" width="377" height="203" /></a></p>
<p>Not every browser support this property although it was omitted by ECMA</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2012/01/29/javascript-callee-property/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to easily search SQL stored procedures and objects</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2010/10/26/how-to-easily-search-sql-stored-procedures-and-objects/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2010/10/26/how-to-easily-search-sql-stored-procedures-and-objects/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 09:57:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=731620</guid>
		<description><![CDATA[Hi all, Lately I have been working on a Migration project in which I had to move data from an old SQL DB into a new one with a different schema (slightly different). In order to understand the differences I downloaded several free tool in which I could compare both schema. There are lots of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Hi all, Lately I have been working on a Migration project in which I had to move data from an old SQL DB into a new one with a different schema (slightly different). In order to understand the differences I downloaded several free tool in which I could compare both schema. There are lots of good tool for that but during the project I also had to look out for things like:</p>
<p>1. Which stored procedures and Tables FK uses a given column?</p>
<p>2. Which tables contains a given ID</p>
<p>and much much more questions of that kind. So instead of using a stored procedures and system tables to perform the task I have found out that there is a free tool from the “Redgate” company that does exactly that:It is called “SQL Search” and here are some snap shots to let you understand how it works.&#160; (BTW it is fully integrated with SQL management studio 2005, 2008).</p>
<p><a href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_2AA00583.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_633A89C3.png" width="495" height="272" /></a> </p>
<p>(You can filter which object types you want to search in : Tables, SP, Views etc)</p>
<p><a href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_0F66EADB.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_2D35490F.png" width="506" height="273" /></a> </p>
<p>Once clicked you can see the text and move to the SP.</p>
<p><a href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_6F0C0890.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_6E8FAFCE.png" width="515" height="265" /></a> </p>
<p>Here is the link for the download:<a title="http://www.red-gate.com/products/SQL_Search/index.htm" href="http://www.red-gate.com/products/SQL_Search/index.htm">http://www.red-gate.com/products/SQL_Search/index.htm</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2010/10/26/how-to-easily-search-sql-stored-procedures-and-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET Ajax 4/3.5 CDN support</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2010/06/17/aspnet-ajax-435-cdn-support/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2010/06/17/aspnet-ajax-435-cdn-support/#respond</comments>
		<pubDate>Thu, 17 Jun 2010 11:53:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[ASP.NET Ajax 4.0]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=662176</guid>
		<description><![CDATA[Today I found out a cool nice thing. As we all know Microsoft ASP.NET Ajax 4.0 is shipped with the new caching support for the JS library it uses. This feature is called the CDN and basically it is working and increasing performance by spreading lots of servers around the world that store JS files [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><P>Today I found out a cool nice thing. As we all know Microsoft ASP.NET Ajax 4.0 is shipped with the new caching support for the JS library it uses. This feature is called the CDN and basically it is working and increasing performance by spreading lots of servers around the world that store JS files like the ASP.NET Ajax 4.0 and the Jquery library files.</P><br />
<P>From Microsoft: “By taking advantage of the Microsoft Ajax CDN, you can significantly improve the performance of your Ajax applications. The contents of the Microsoft Ajax CDN are cached on servers located around the world”</P><br />
<P>For a list of all available files <A href="http://www.asp.net/ajaxlibrary/CDN.ashx" target=_blank mce_href="http://www.asp.net/ajaxlibrary/CDN.ashx">check this site.</A></P><br />
<P>What if your application is ASP.NET 3.5 and not 4.0 and you are not using or whishing to upgrade to the 4.0 version. Well you can still use the CDN. Microsoft added the 3.5 Js files to the CDN as well.</P><br />
<P>The 2 files available are the </P><br />
<P>&nbsp;<A href="http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.debug.js" mce_href="http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.debug.js">http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.debug.js</A></P><br />
<P>&nbsp;<A href="http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js" mce_href="http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js">http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js</A></P><br />
<P>You can use them by using the Script manager like this:</P><br />
<P><CODE><SCRIPTMANAGER id=SCRIPTMANAGER1 enablepartialrendering="false" runat="server"><SCRIPTS><SCRIPTREFERENCE name="MicrosoftAjax.js" path="http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js"></SCRIPTREFERENCE></SCRIPTS></SCRIPTMANAGER></CODE></P><br />
<DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">asp</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: #a31515">ScriptManager</SPAN> <SPAN style="COLOR: red">ID</SPAN><SPAN style="COLOR: blue">=&quot;SCRIPTMANAGER1&quot;</SPAN> <SPAN style="COLOR: red">EnablePartialRendering</SPAN><SPAN style="COLOR: blue">=&quot;false&quot;</SPAN> <SPAN style="COLOR: red">runat</SPAN><SPAN style="COLOR: blue">=&quot;server&quot;&gt;</SPAN></P><br />
<P style="MARGIN: 0px">&nbsp;<SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">Scripts</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue">&nbsp;&nbsp;&nbsp;&nbsp; &lt;</SPAN><SPAN style="COLOR: #a31515">asp</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: #a31515">ScriptReference</SPAN> <SPAN style="COLOR: red">Name</SPAN><SPAN style="COLOR: blue">=&quot;MicrosoftAjax.js&quot;</SPAN> <SPAN style="COLOR: red"></SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: red">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Path</SPAN><SPAN style="COLOR: blue">=&quot;http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js&quot;</SPAN> <SPAN style="COLOR: blue">/&gt;</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P><br />
<P style="MARGIN: 0px">&nbsp;<SPAN style="COLOR: blue">&lt;/</SPAN><SPAN style="COLOR: #a31515">Scripts</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue">&lt;/</SPAN><SPAN style="COLOR: #a31515">asp</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: #a31515">ScriptManager</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue"></SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue">Enjoy</SPAN></P></DIV></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2010/06/17/aspnet-ajax-435-cdn-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding/Firing custom event using JavaScript</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2010/05/16/addingfiring-custom-event-using-javascript/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2010/05/16/addingfiring-custom-event-using-javascript/#comments</comments>
		<pubDate>Sun, 16 May 2010 13:42:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=620181</guid>
		<description><![CDATA[Today I found out a very cool way for adding custom events and fire them for any Client side object. This can be done using ASP.NET Ajax very easily. (Thank you Igor). In order to create these events and fire them we will use the Sys.EventHandlerList Class. This class Creates a dictionary of client events [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><P>Today I found out a very cool way for adding custom events and fire them for any Client side object. This can be done using ASP.NET Ajax very easily. (Thank you Igor).</P><br />
<P>In order to create these events and fire them we will use the <A href="http://msdn.microsoft.com/en-us/library/bb383996.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb383996.aspx">Sys.EventHandlerList Class</A>. This class Creates a dictionary of client events for a component, with event names as keys and the associated handlers as values. It’s main method we need are the addHandler and getHandler. Lets see a simple example which is pretty self explanatory.</P><br />
<P>This sample creates a Book and a Library “classes”. The Library class will have a Add and a GetBook method that will fire an event when ever they are called. Here is the Code: (And again it is pretty self explanatory)</P><br />
<DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 11</SPAN>&nbsp;<SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">form</SPAN> <SPAN style="COLOR: red">id</SPAN><SPAN style="COLOR: blue">=&quot;form1&quot;</SPAN> <SPAN style="COLOR: red">runat</SPAN><SPAN style="COLOR: blue">=&quot;server&quot;&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 12</SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">asp</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: #a31515">ScriptManager</SPAN> <SPAN style="COLOR: red">runat</SPAN><SPAN style="COLOR: blue">=server</SPAN> <SPAN style="COLOR: red">ID</SPAN><SPAN style="COLOR: blue">=&quot;SM&quot;&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 13</SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;/</SPAN><SPAN style="COLOR: #a31515">asp</SPAN><SPAN style="COLOR: blue">:</SPAN><SPAN style="COLOR: #a31515">ScriptManager</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 14</SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">div</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 15</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 16</SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;/</SPAN><SPAN style="COLOR: #a31515">div</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 17</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 18</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;</SPAN><SPAN style="COLOR: #a31515">script</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 19</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">function</SPAN> Enums() {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 21</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">throw</SPAN> Error.notImplemented();</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 22</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 23</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 24</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enums.ActionType = { Add: <SPAN style="COLOR: #a31515">&quot;Add&quot;</SPAN>, Get: <SPAN style="COLOR: #a31515">&quot;Get&quot;</SPAN> }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 26</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 27</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 28</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">function</SPAN> Book(name) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 29</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>.Name = name;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 30</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 31</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 32</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">function</SPAN> Library() {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 33</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>.Books = [];</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 34</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 35</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 36</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Library.prototype.Add = <SPAN style="COLOR: blue">function</SPAN>(book) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 37</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>.Books[<SPAN style="COLOR: blue">this</SPAN>.Books.length] = book;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 38</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 39</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>.fireEvent(Enums.ActionType.Add, book);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 40</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 41</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 42</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Library.prototype.GetBook = <SPAN style="COLOR: blue">function</SPAN>(bookName) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 43</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">var</SPAN> retval = <SPAN style="COLOR: blue">null</SPAN>;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 44</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">var</SPAN> x = 0; x &lt; <SPAN style="COLOR: blue">this</SPAN>.Books.length; x++) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 45</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">if</SPAN> (<SPAN style="COLOR: blue">this</SPAN>.Books[x].Name == bookName) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 46</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval = <SPAN style="COLOR: blue">this</SPAN>.Books[x];</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 47</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 48</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 49</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>.fireEvent(Enums.ActionType.Get, retval);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 50</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">return</SPAN> retval;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 51</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 52</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 53</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Library.prototype.addHandler = <SPAN style="COLOR: blue">function</SPAN>(eventId, handler) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 54</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">if</SPAN> (!<SPAN style="COLOR: blue">this</SPAN>._events) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 55</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>._events = <SPAN style="COLOR: blue">new</SPAN> Sys.EventHandlerList();</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 56</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 57</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">this</SPAN>._events.addHandler(eventId, handler);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 58</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 59</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 60</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Library.prototype.fireEvent = <SPAN style="COLOR: blue">function</SPAN>(eventId, book) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 61</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">var</SPAN> events = <SPAN style="COLOR: blue">this</SPAN>._events;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 62</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">if</SPAN> (!events) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 63</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">return</SPAN> <SPAN style="COLOR: blue">false</SPAN>;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 64</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 65</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 66</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">var</SPAN> handler = events.getHandler(eventId);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 67</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">if</SPAN> (handler) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 68</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handler(book);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 69</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 70</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 71</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 72</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">var</SPAN> lib = <SPAN style="COLOR: blue">new</SPAN> Library();</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 73</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lib.addHandler(Enums.ActionType.Add, BookAdded);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 74</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lib.addHandler(Enums.ActionType.Get, BookUpdated);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 75</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 76</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 77</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">function</SPAN> BookAdded(book) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 78</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(<SPAN style="COLOR: #a31515">&quot;A book was added:&quot;</SPAN> + book.Name);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 79</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 80</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 81</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">function</SPAN> BookUpdated(book) {</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 82</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(<SPAN style="COLOR: #a31515">&quot;A book was updated:&quot;</SPAN> + book.Name);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 83</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 84</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 85</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lib.Add(<SPAN style="COLOR: blue">new</SPAN> Book(<SPAN style="COLOR: #a31515">&quot;C# book&quot;</SPAN>));</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 86</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lib.Add(<SPAN style="COLOR: blue">new</SPAN> Book(<SPAN style="COLOR: #a31515">&quot;VB.NET book&quot;</SPAN>));</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 87</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lib.GetBook(<SPAN style="COLOR: #a31515">&quot;C# book&quot;</SPAN>);</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 88</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 89</SPAN>&nbsp;</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 90</SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;/</SPAN><SPAN style="COLOR: #a31515">script</SPAN><SPAN style="COLOR: blue">&gt;</SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">&nbsp;&nbsp; 91</SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">&lt;/</SPAN><SPAN style="COLOR: #a31515">form</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></P></DIV><br />
<P>Enjoy.</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2010/05/16/addingfiring-custom-event-using-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ever forgot “alert()” when deployed to production</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2010/04/25/ever-forgot-alert-when-deployed-to-production/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2010/04/25/ever-forgot-alert-when-deployed-to-production/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 09:04:48 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=597146</guid>
		<description><![CDATA[As developers we often forget to remove debug code on the client side such as “alert” calls , “debugger” statements and so on. So in order to avoid our team leader throw a chair at us here is a simple solution to this problem: On the page startup ( page load or when ever you [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><font size="3">As developers we often forget to remove debug code on the client side such as “alert” calls , “debugger” statements and so on. So in order to avoid our team leader throw a chair at us here is a simple solution to this problem:</font></p>
<p><font size="3">On the page startup ( page load or when ever you find it necessary) simply override the alert method like this:</font></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green"><font size="3">Set alert to work only in debug</font></span></p>
<p style="margin: 0px"><font size="3"><span style="color: blue">var</span> originalAler = window.alert;</font></p>
<p style="margin: 0px"><font size="3">window.alert = <span style="color: blue">function</span>(message) {</font></p>
<p style="margin: 0px"><font size="3"><span style="color: blue">if</span> (Sys.Debug.isDebug) {</font></p>
<p style="margin: 0px"><font size="3">&#160;&#160; originalAler(message);</font></p>
<p style="margin: 0px"><font size="3"> }</font></p>
<p style="margin: 0px"><font size="3">}</font></p>
<p style="margin: 0px"><font size="3"></font></p>
<p style="margin: 0px"><font size="3">What i am doing here is to save the original alert method in a variable(delegate) and when someone uses the alert message simply check if we are in debug mode (I used ASP.NET Ajax) and call the original alert.</font></p>
<p style="margin: 0px"><font size="3"></font></p>
<p style="margin: 0px"><font size="3">Enjoy.</font></p>
<p style="margin: 0px"><font size="3">&#160;</font></p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2010/04/25/ever-forgot-alert-when-deployed-to-production/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using C# 4 to implement lazy initialization</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2010/04/08/using-c-4-to-implement-lazy-initialization/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2010/04/08/using-c-4-to-implement-lazy-initialization/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 10:02:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[C# 4]]></category>
		<category><![CDATA[Dev]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=578522</guid>
		<description><![CDATA[Sometimes we wish to improve performance and improve memory usage by making sure the Object we create and initialize is really needed. A couple of scenarios that we might thing of are: We have an object that is expensive to create and there might be situations when we don't really need it. Lets say we [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><P><FONT size=3>Sometimes we wish to improve performance and improve memory usage by making sure the Object we create and initialize is really needed. A couple of scenarios that we might thing of are:</FONT></P><br />
<BLOCKQUOTE><br />
<UL><br />
<LI><br />
<P><FONT size=3>We have an object that is expensive to create and there might be situations when we don't really need it. Lets say we have an <STRONG>Employee</STRONG> object in memory and this <STRONG>Employee</STRONG> has a property by the name <STRONG>FormerEmployers</STRONG> that describe all the places he worked at. This information is initialized from a DB. If the consumer of this <STRONG>Employee</STRONG> object never reading this data there is no sense filling the memory and bringing this data.</FONT></P></LI></UL><br />
<UL><br />
<UL><FONT size=3></FONT></UL><br />
<UL><FONT size=3></FONT></UL><br />
<LI><br />
<P><FONT size=3>We have an expensive Object to create but we want it’s creation only after other expensive objects have created. An example for this is a creation of some large arrays or lists when the application first loads but the other are not necessary immediately.</FONT></P></LI></UL></BLOCKQUOTE><br />
<P><FONT size=3>Up until now days we had to implement this laziness by ourselves. Now we can use the </FONT><A href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx"><FONT size=3>Lazy&lt;T&gt;</FONT></A><FONT size=3> within .NET 4.</FONT></P><br />
<P><U><STRONG><FONT size=4>Her are some samples and expiations from MSDN:</FONT></STRONG></U></P><br />
<P><STRONG><U></U></STRONG></P><br />
<DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"><br />
<P style="MARGIN: 0px">To define a lazy-initialized type, for example, <STRONG>MyType</STRONG>, use Lazy&lt;MyType&gt; (Lazy(Of MyType) in Visual Basic), as shown in the following example. If no delegate is passed in the <A href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx">Lazy&lt;T&gt;</A> constructor, the wrapped type is created by using ActivatorCreateInstance() when the value property is first accessed. If the type does not have a default constructor, a run-time exception is thrown.</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// Initialize by invoking a specific constructor on Order when Value</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// property is accessed</SPAN></P><br />
<P style="MARGIN: 0px">Lazy&lt;Orders&gt; _orders = <SPAN style="COLOR: blue">new</SPAN> Lazy&lt;Orders&gt;(() =&gt; <SPAN style="COLOR: blue">new</SPAN> Orders(100));</P><br />
<P style="MARGIN: 0px">You can also pass a delegate in the <A href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx">Lazy&lt;T&gt;</A> constructor that invokes a specific constructor overload on the wrapped type at creation time, and perform any other initialization steps that are required, as shown in the following example.</P></DIV><br />
<DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// Initialize by invoking a specific constructor on Order when Value</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// property is accessed</SPAN></P><br />
<P style="MARGIN: 0px">Lazy&lt;Orders&gt; _orders = <SPAN style="COLOR: blue">new</SPAN> Lazy&lt;Orders&gt;(() =&gt; <SPAN style="COLOR: blue">new</SPAN> Orders(100));</P><br />
<P style="MARGIN: 0px">After the Lazy object is created, no instance of <STRONG>Orders</STRONG> is created until the <A href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx">Value</A> property of the Lazy variable is accessed for the first time. On first access, the wrapped type is created and returned, and stored for any future access.</P><br />
<DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green"></SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// We need to create the array only if displayOrders is true</SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue">if</SPAN> (displayOrders == <SPAN style="COLOR: blue">true</SPAN>)</P><br />
<P style="MARGIN: 0px">{</P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp; DisplayOrders(_orders.Value.OrderData);</P><br />
<P style="MARGIN: 0px">}</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: blue">else</SPAN></P><br />
<P style="MARGIN: 0px">{</P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: green">// Don't waste resources getting order data.</SPAN></P><br />
<P style="MARGIN: 0px">}</P><br />
<P style="MARGIN: 0px"><FONT color=#000080 size=5>Thread–safe Initialization</FONT></P></DIV><br />
<P>Some <A href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642331(v=VS.100).aspx">Lazy&lt;T&gt;</A> constructor overloads have a Boolean parameter named isThreadSafe that is used to specify whether the <A href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx">Value</A> property will be accessed from multiple threads. If you intend to access the property from just one thread, pass in false to obtain a modest performance benefit. If you intend to access the property from multiple threads, pass in true to instruct the Lazy instance to correctly handle race conditions in which one thread throws an exception at initialization time. If you use a constructor that does not have the isThreadSafe parameter, the value defaults to true.</P><br />
<P>In multi-threaded scenarios, the first thread to access the <A href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx">Value</A> property initializes it for all subsequent accesses on all threads, and all threads share the same data. Therefore, it does not matter which thread initializes the object, and race conditions are benign. If the first thread to initialize <A href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx">Value</A> causes an exception to be thrown, that same exception will be thrown for all subsequent accesses of <A href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd642177(v=VS.100).aspx">Value</A>. It is not possible for one thread to raise an exception and another to initialize the object. The following example shows that the same Lazy&lt;int&gt; instance has the same value for three separate threads.</P></DIV><br />
<P mce_keep="true">&nbsp;</P><br />
<DIV style="FONT-FAMILY: courier new; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// Initialize the integer to the managed thread id of the </SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">// first thread that accesses the Value property.</SPAN></P><br />
<P style="MARGIN: 0px">Lazy&lt;<SPAN style="COLOR: blue">int</SPAN>&gt; number = <SPAN style="COLOR: blue">new</SPAN> Lazy&lt;<SPAN style="COLOR: blue">int</SPAN>&gt;(() =&gt; Thread.CurrentThread.ManagedThreadId);</P><br />
<P style="MARGIN: 0px">Thread t1 = <SPAN style="COLOR: blue">new</SPAN> Thread(() =&gt; <SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(<SPAN style="COLOR: #a31515">&quot;number on t1 = {0} ThreadID = {1}&quot;</SPAN>,</P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number.Value, </P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.CurrentThread.ManagedThreadId));</P><br />
<P style="MARGIN: 0px">t1.Start();</P><br />
<P style="MARGIN: 0px">Thread t2 = <SPAN style="COLOR: blue">new</SPAN> Thread(() =&gt; <SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(<SPAN style="COLOR: #a31515">&quot;number on t2 = {0} ThreadID = {1}&quot;</SPAN>,</P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number.Value, </P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.CurrentThread.ManagedThreadId));</P><br />
<P style="MARGIN: 0px">t2.Start();</P><br />
<P style="MARGIN: 0px">Thread t3 = <SPAN style="COLOR: blue">new</SPAN> Thread(() =&gt; <SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(<SPAN style="COLOR: #a31515">&quot;number on t3 = {0} ThreadID = {1}&quot;</SPAN>, </P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number.Value, </P><br />
<P style="MARGIN: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.CurrentThread.ManagedThreadId));</P><br />
<P style="MARGIN: 0px">t3.Start();</P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">//Ensure that thread IDs are not recycled if the </SPAN></P><br />
<P style="MARGIN: 0px"><SPAN style="COLOR: green">//first thread completes before the last one starts.</SPAN></P><br />
<P style="MARGIN: 0px">t1.Join();</P><br />
<P style="MARGIN: 0px">t2.Join();</P><br />
<P style="MARGIN: 0px">t3.Join();</P></DIV><br />
<P><FONT size=4>Enjoy <img src="https://s.w.org/images/core/emoji/11/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></FONT></P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2010/04/08/using-c-4-to-implement-lazy-initialization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET 4.0 New features – HTML, JS, ASP.NET Snippets</title>
		<link>http://blogs.microsoft.co.il/pini_dayan/2009/11/30/aspnet-40-new-features-html-js-aspnet-snippets/</link>
		<comments>http://blogs.microsoft.co.il/pini_dayan/2009/11/30/aspnet-40-new-features-html-js-aspnet-snippets/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 09:55:00 +0000</pubDate>
		<dc:creator><![CDATA[Pini Dayan]]></dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blogs.microsoft.co.il/?p=456262</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; In previous version of VS.NET we encountered the new snippet solution for creating a chunk of code that is usually reusable and then using it during programming or even lecturing. This feature was available for both C# and VB.NET coders. But we could not create or use snippets for the markup we are writing [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_0BD2F233.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_0BD2F233.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_6DAF7742.png" width=244 height=62 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_6DAF7742.png"></A></P></BLOCKQUOTE><br />
<P>In previous version of VS.NET we encountered the new snippet solution for creating a chunk of code that is usually reusable and then using it during programming or even lecturing. This feature was available for both C# and VB.NET coders. But we could not create or use snippets for the markup we are writing like HTML, JavaScript or even the ASP.NET page. VS.NET 2010 allows us to do just that!</P><br />
<P>Lets see some of the “out of the box” snippets we can use:</P><br />
<P><STRONG>HTML Snippets:</STRONG></P><br />
<P><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_6C6D6F14.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_6C6D6F14.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_529BC996.png" width=410 height=250 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_529BC996.png"></A>&nbsp; </P><br />
<P mce_keep="true">&nbsp;</P><br />
<P>AS you can see the same snippet sign is now available on the ASPX page side.&nbsp; So for example if I choose the checkbox snippet and double tab click it i will get the following markup:</P><br />
<P><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_385DF123.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_385DF123.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_12F68E66.png" width=244 height=39 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_12F68E66.png"></A></P><br />
<P><STRONG>JavaScript Snippets:</STRONG></P><br />
<P>Let move even further and see a much useful sample. Most of us are writing JavaScript and lots of it in our web application, so lets see what is available out of the box for us in JavaScript :</P><br />
<P>alert snippet,control snippet,create snippet, do for while snippets, if else snippets and much much more. Here for example I am using the for snippet for creating a for clause.</P><br />
<P><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_72DE1259.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_72DE1259.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_719C0A2B.png" width=244 height=68 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_719C0A2B.png"></A> </P><br />
<P><STRONG>ASP.NET snippets:</STRONG></P><br />
<P>We have some useful control declarations as a snippets such as updatepanel, sqldatasource , all the validator controls and much much more.</P><br />
<P><STRONG>Creating our own custom snippets:</STRONG></P><br />
<P>Wouldn’t it be great to create our own snippets since we are the ones knowing what markup we most commonly using. So before showing how to accomplish this, Here is how you can see the entire list of snippets.</P><br />
<BLOCKQUOTE><br />
<P>In the VS.NET 2010 , clicj the tool menu and open the “code&nbsp; snippets manager” <BR><A href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_5C40E574.png" mce_href="http://blogs.microsoft.co.il/blogs/pini_dayan/image_5C40E574.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_605054A8.png" width=355 height=279 mce_src="http://blogs.microsoft.co.il/blogs/pini_dayan/image_thumb_605054A8.png"></A>&nbsp;</P><br />
<P>This snippet manager will now show you all the HTML, ASP.NET snippets or the JS snippets if you choose Jscript in the language select box. So in order to add them simply use this manager and read how to create the snippet files <A href="http://www.switchonthecode.com/tutorials/csharp-tutorial-visual-studio-code-snippets" target=_blank mce_href="http://www.switchonthecode.com/tutorials/csharp-tutorial-visual-studio-code-snippets">here</A>.</P></BLOCKQUOTE><br />
<P><STRONG>Surround with feature:</STRONG></P><br />
<P>Another cool thing we have in C# and is really useful is the “surround with” . We can for example write some JS code and then decide we want to surround it with a function. Simply select the wanted Js , right click and choose “surround with” .</P><br />
<P>Enjoy.</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.microsoft.co.il/pini_dayan/2009/11/30/aspnet-40-new-features-html-js-aspnet-snippets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
