<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://live.mscommunity.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Weblog :: Boris Ševo</title><link>http://live.mscommunity.net/blogs/borissevo/default.aspx</link><description>Sporadic posts about my interests, e.g. software development (mostly .NET), technology in general and some occasional rant.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>Anchor is not clickable in Firefox and Safari when it's inside of the div tag which has image as background</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/12/11/anchor-is-not-clickable-in-firefox-and-safari-when-it-s-placed-inside-div-tag-with-image-as-background.aspx</link><pubDate>Thu, 11 Dec 2008 15:05:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:14641</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=14641</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/12/11/anchor-is-not-clickable-in-firefox-and-safari-when-it-s-placed-inside-div-tag-with-image-as-background.aspx#comments</comments><description>&lt;p&gt;That&amp;#39;s one of mine older issues which I was facing few months ago and today, while I was browsing through my pending blog posts, I decided to post few words about it hoping that it will save you few minutes of work if you ran into the same problem as I was.&lt;/p&gt;

&lt;p&gt;So, let&amp;#39;s imagine that you want to put some link (anchor tag) inside a div tag which has some image as a background and that your link need to positioned somewhere inside of the image (div&amp;#39;s background). Your HTML code will then be something like this:&lt;/p&gt;

&lt;pre&gt;&amp;lt;div class=&amp;quot;divsCSSClass&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;a href=&amp;quot;Default.aspx&amp;quot; style=&amp;quot;left: 133px; position:relative; top: 7px;&amp;quot;&amp;gt;&lt;br /&gt;            some_text&lt;br /&gt;     &amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;p&gt;and your CSS will then be something like this:&lt;/p&gt;

&lt;pre&gt;.divsCSSClass {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; background: url(&amp;#39;image_name.png&amp;#39;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width:392px;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height:45px;&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;Above code will work in IE and Opera, but in Firefox and Safari link (anchor) will not be clickable. The solution is extremely simple. All you need to do is to add &lt;i&gt;position:relative;&lt;/i&gt; to div&amp;#39;s CSS class. CSS will then be something like this:&lt;/p&gt;

&lt;pre&gt;&amp;nbsp;.divsCSSClass {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; background: url(&amp;#39;image_name.png&amp;#39;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width:392px;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; height:45px;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;u&gt;&lt;b&gt;position: relative;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;}&lt;/pre&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=14641" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/CSS/default.aspx">CSS</category><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/Firefox/default.aspx">Firefox</category></item><item><title>Using jQuery to prevent form submit when enter is pressed</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/12/11/using-jquery-to-prevent-form-submit-when-enter-is-pressed.aspx</link><pubDate>Thu, 11 Dec 2008 10:51:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:14632</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=14632</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/12/11/using-jquery-to-prevent-form-submit-when-enter-is-pressed.aspx#comments</comments><description>&lt;p&gt;I was recently working on a ASP.NET RIA which has a web form with the input field in which users can type some search term and press the search button or hit enter key. Search is invoked by an asynchronous call and done on the server. The text field is placed inside of &lt;i&gt;form&lt;/i&gt; tag and because of that, when someone hits the enter key, instead of the desired behavior (asynchronous call), the whole form is submitted to the server. There is more then one possible solution for this kind of problem, but because I was already using jQuery for building the whole application&amp;#39;s UI, I fixed the problem with the following elegant jQuery&amp;#39;s cross-browser code snippet:&lt;/p&gt;

&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(document).ready(function() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;$(&amp;quot;form&amp;quot;).bind(&amp;quot;keypress&amp;quot;, function(e) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (e.keyCode == 13) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/b&gt;search($(&amp;quot;#searchTerm&amp;quot;).attr(&amp;#39;value&amp;#39;));&lt;b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }); &lt;/pre&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=14632" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>Testing tool for multithreaded applications from Microsoft Research</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/11/22/testing-tool-for-multithreaded-applications-from-microsoft-research.aspx</link><pubDate>Sat, 22 Nov 2008 09:34:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:14385</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=14385</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/11/22/testing-tool-for-multithreaded-applications-from-microsoft-research.aspx#comments</comments><description>
&lt;p&gt;Microsoft Research has released &lt;a href="http://research.microsoft.com/projects/CHESS/"&gt;CHESS&lt;/a&gt;,
an automated tool for finding errors like data-races, deadlocks, and hangs in multithreaded applications by systematically exploring thread schedules (it has even discovered bug in PLINQ). Once error is located, CHESS provides a fully repeatable execution
of the program leading to the error. Win32 version can be downloaded &lt;a href="http://research.microsoft.com/research/downloads/details/b23f8dc3-bb73-498f-bd85-1de121672e69/details.aspx"&gt;here&lt;/a&gt; (at this time license is only for academic use) and commercial version will hopefully be available soon.&lt;br /&gt;&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=14385" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/concurrent+programming/default.aspx">concurrent programming</category></item><item><title>Hotfix for WPF designer</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/11/19/hotfix-for-wpf-designer.aspx</link><pubDate>Wed, 19 Nov 2008 11:46:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:14368</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=14368</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/11/19/hotfix-for-wpf-designer.aspx#comments</comments><description>&lt;p&gt;If you are working with WPF you should consider downloading the hotfix which can be found &lt;a href="http://code.msdn.microsoft.com/KB958017"&gt;here&lt;/a&gt;. If you have Silverlight Tools for VS 2008 SP1 you shouldn&amp;#39;t install this hotfix because it already includes it.&lt;br /&gt;&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=14368" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/WPF/default.aspx">WPF</category></item><item><title>WPF trick #2 - Alternate background colors for ListView rows</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/21/wpf-trick-1-alternate-background-colors-for-listview-rows.aspx</link><pubDate>Tue, 21 Oct 2008 14:22:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:13799</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=13799</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/21/wpf-trick-1-alternate-background-colors-for-listview-rows.aspx#comments</comments><description>&lt;p&gt;Prior the .NET Framework 3.5 SP1 was released, if you want to set alternate background colors for ListView rows you needed to write some kind Converter which returnes some kind of Brush. IF you have SP1 installed accomplishing the same functionality is rather trivial job. Here are the code snippets:&lt;/p&gt;

&lt;p&gt;(defining the style)&lt;/p&gt;

&lt;pre&gt;    &amp;lt;Style x:Key=&amp;quot;&lt;b&gt;CustomListViewItemStyle&lt;/b&gt;&amp;quot; TargetType=&amp;quot;{x:Type ListViewItem}&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;Style.Triggers&amp;gt;&lt;br /&gt;            &amp;lt;Trigger Property=&amp;quot;ItemsControl.AlternationIndex&amp;quot; Value=&amp;quot;&lt;b&gt;0&lt;/b&gt;&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;Setter Property=&amp;quot;Background&amp;quot; Value=&amp;quot;#2C2C2C&amp;quot;&amp;gt;&amp;lt;/Setter&amp;gt;&lt;br /&gt;            &amp;lt;/Trigger&amp;gt;&lt;br /&gt;            &amp;lt;Trigger Property=&amp;quot;ItemsControl.AlternationIndex&amp;quot; Value=&amp;quot;&lt;b&gt;1&lt;/b&gt;&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;Setter Property=&amp;quot;Background&amp;quot; Value=&amp;quot;#262626&amp;quot;&amp;gt;&amp;lt;/Setter&amp;gt;&lt;br /&gt;            &amp;lt;/Trigger&amp;gt;&lt;br /&gt;        &amp;lt;/Style.Triggers&amp;gt;&lt;br /&gt;    &amp;lt;/Style&amp;gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;(using the defined style)&lt;/p&gt;
&lt;pre&gt;    &amp;lt;ListView ItemContainerStyle=&amp;quot;{DynamicResource &lt;b&gt;CustomListViewItemStyle&lt;/b&gt;}&amp;quot;&lt;br /&gt;             &lt;b&gt; AlternationCount=&amp;quot;2&amp;quot;&lt;/b&gt;&amp;gt;&lt;br /&gt;        ...&lt;br /&gt;    &amp;lt;/ListView&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=13799" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/WPF/default.aspx">WPF</category></item><item><title>WPF trick #1 - Hyperlink control</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/21/wpf-trick-1-hyperlink-control.aspx</link><pubDate>Tue, 21 Oct 2008 08:13:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:13759</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=13759</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/21/wpf-trick-1-hyperlink-control.aspx#comments</comments><description>
&lt;p&gt;Today I needed to create a simple grid which will hold some text information about some products and a few Hyperlink controls which when clicked need to display detailed information about particular product. On my big surprise WPF doesn&amp;#39;t have Hyperlink control. This is really weird, but the solution is very simple. All you need to do is to use &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink.aspx"&gt;System.Windows.Documents.Hyperlink&lt;/a&gt; in a combination with &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.aspx"&gt;TextBlock&lt;/a&gt; control.&lt;/p&gt;

&lt;p&gt;XAML code for creating Hyperlink &amp;#39;control&amp;#39; is then something like this:&lt;/p&gt;

&lt;pre&gt;    
    &amp;lt;TextBlock&amp;gt;
        &amp;lt;Hyperlink&amp;gt;
            &amp;lt;TextBlock Text=&amp;quot;Some text&amp;quot;&amp;gt;
        &amp;lt;/Hyperlink&amp;gt;
    &amp;lt;/TextBlock&amp;gt;
&lt;/pre&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=13759" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Silverlight 2 now available</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/14/silverlight-2-now-available.aspx</link><pubDate>Tue, 14 Oct 2008 08:06:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:12827</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=12827</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/14/silverlight-2-now-available.aspx#comments</comments><description>
&lt;p&gt;More info &lt;a href="http://www.microsoft.com/presspass/press/2008/oct08/10-13Silverlight2PR.mspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=12827" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight 2 RC0 offline documentation</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/05/silverlight-2-rc0-offline-documentation.aspx</link><pubDate>Sun, 05 Oct 2008 19:39:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:11639</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=11639</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/10/05/silverlight-2-rc0-offline-documentation.aspx#comments</comments><description>
&lt;p&gt;&amp;nbsp;You can get RC0 offline documentation &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=silverlightsdk&amp;amp;DownloadId=3304"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=11639" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Geppeto project or what some smart people on FER are doing when they are not teaching the students</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/06/11/geppeto-project-or-what-some-smart-people-on-fer-are-doing-when-they-are-not-teaching-the-students.aspx</link><pubDate>Wed, 11 Jun 2008 21:16:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:3806</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=3806</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/06/11/geppeto-project-or-what-some-smart-people-on-fer-are-doing-when-they-are-not-teaching-the-students.aspx#comments</comments><description>&lt;p&gt;Last year Tomislav Bronzin allready &lt;a href="http://blogs.mscommunity.net/blogs/tbronzin/archive/2007/11/03/google-gadget-to-gadget-communication-based-on-research-of-two-young-croatian-scientists.aspx"&gt;wrote&lt;/a&gt; about Gadget-to-Gadget communication project which researchers at &lt;a href="http://www.fer.hr/"&gt;FER&lt;/a&gt; (Faculty of Electrical Engineering and Computing in Zagreb) were doing for Google. If you are curious in what Gadget-to-Gadget communication evolved, you can take look at this &lt;a href="http://www.youtube.com/watch?v=fbUvCdADz_A"&gt;YouTube video&lt;/a&gt; and see how will one day some non-skilled end user be able to develop a new gadget for iGoogle platform.&lt;br /&gt;&lt;/p&gt;&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=3806" width="1" height="1"&gt;</description></item><item><title>ASP.NET AJAX - Why should you prefer web service method calls over page method calls?</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/05/19/asp-net-ajax-why-should-you-prefer-web-service-method-calls-over-page-method-calls.aspx</link><pubDate>Mon, 19 May 2008 14:13:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:3472</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=3472</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/05/19/asp-net-ajax-why-should-you-prefer-web-service-method-calls-over-page-method-calls.aspx#comments</comments><description>&lt;p&gt;When you are developing some kind of Ajax powered web page and you need to transfer some data back and forth 
	between the web browser and the web server, you have more then one way to do it. 
	One way is to be lazy and do your job quickly using UpdatePanel. This is probably the easiest way, but it&amp;#39;s certainly not 
	the best way. There is many posts about performance problems related with UpadatePanel 
	and &lt;a href="http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/"&gt;here&lt;/a&gt; 
	is just one of them. If you care about the performance you will transfer your 
	data on some other way. ASP.NET AJAX offers two other ways to do it:&lt;/p&gt;
		&lt;ul&gt;
			&lt;li&gt;calling web service methods&lt;/li&gt;
			&lt;li&gt;calling page methods&lt;/li&gt;
		&lt;/ul&gt;
	&lt;p&gt;There is also many posts about both of them and some people are saying that you should prefer web services, some are saying
	that you should prefer page methods and some are saying that they are both the same. So, the questions is who 
	has right? Well, in last 
	few days I tested both of them and come to the conclusion that they are pretty much the same, but &lt;b&gt;when performances are 
	really important, you should definitely prefer web services&lt;/b&gt;. There are two reasons for that:
	&lt;/p&gt;
	&lt;ol&gt;
		&lt;li&gt;You can execute web service methods asynchronously&lt;/li&gt;
		&lt;li&gt;In page methods you can&amp;#39;t disable session, in web services you can&lt;/li&gt;
	&lt;/ol&gt;
	&lt;p&gt;Page methods and web service methods are called asynchronously on the client, but on the server they are processed synchronously. This basically means 
	that ASP.NET will pick one CLR thread for every incoming request and will not release it and return it to the CLR tread pool as long as request is 
	processed. If request processing is fast you can live with it. But, if there are many concurrent requests and if requests processing involves 
	relatively long waiting for external I/O operations to complete (for example database queries) you will soon run into problems because there will not 
	be any free CLR threads to process other requests. If you have this kind of problem with the web forms you easily fix it using asynchronous pages. 
	&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163463.aspx"&gt;Here&lt;/a&gt; is a nice explanation how to do it. 
	But, how can you make asynchronous web services and web methods? I don&amp;#39;t know if you can do that with page methods, 
	but in &lt;a href="http://www.amazon.com/Building-Web-2-0-Portal-ASP-NET/dp/0596510500"&gt;Omar&amp;#39;s book&lt;/a&gt; you can read how you can do that  
	with web services.&lt;/p&gt;
	&lt;p&gt;Asynchronous request processing is the first reason to prefer web service methods calls over page method calls. But, there is also one more reason 
	and it&amp;#39;s related with the use of session. Using &lt;i&gt;WebMethod&lt;/i&gt; attribute and its &lt;i&gt;EnableSession&lt;/i&gt; property you can disable session on the web service method 
	level. You can try to do the same with the page methods, but session will 
	always be enabled and you will always be able to put some data in &lt;i&gt;Session&lt;/i&gt; object or pull data from it. 
	That means that session will be loaded on every request which will downgrade 
	performances.&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=3472" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/ASP.NET+AJAX/default.aspx">ASP.NET AJAX</category></item><item><title>Silverlight on mobile phones</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/03/05/silverlight-on-mobile-phones.aspx</link><pubDate>Wed, 05 Mar 2008 00:38:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:2189</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=2189</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/03/05/silverlight-on-mobile-phones.aspx#comments</comments><description>
&lt;p&gt;After the &amp;quot;war&amp;quot; between Silverlight and Flash has started on desktop computers, it seems that we have a new battlefield. Yesterday Nokia announced that it will &lt;a href="http://www.nokia.com/A4136001?newsid=1197788"&gt;support Silverlight&lt;/a&gt; on some of its mobile devices. Does this mean that we can expect to see Silverlight on &lt;a href="http://code.google.com/android/"&gt;Android&lt;/a&gt;, &lt;a href="http://www.apple.com/iphone/"&gt;iPhone&lt;/a&gt; and other smartphones? I really hope so.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=2189" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Concurrent programming in C# - Parallel.Do method</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/02/27/concurrent-programming-in-c-parallel-do-method.aspx</link><pubDate>Wed, 27 Feb 2008 00:18:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:2077</guid><dc:creator>boris.sevo</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=2077</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/02/27/concurrent-programming-in-c-parallel-do-method.aspx#comments</comments><description>&lt;p&gt;This is my first one but certainly not the last one post about the &lt;a&gt;concurrent programming&lt;/a&gt; in C#. 
	&lt;a href="http://www.gotw.ca/publications/concurrency-ddj.htm"&gt;Free lunch is 
	over&lt;/a&gt;&lt;br /&gt;is an excellent text which shows why concurrent programming matters. If you ever read anything about it, you&lt;br /&gt;have probably noticed that 
	people talk about it as something hard and complicated. Is it really so hard 
	and&lt;br /&gt;complicated? Well, in my opinion it depends. It depends about how much 
	concurrent your program need to be,&lt;br /&gt;what kind of knowledge do you have about 
	this programming model, which libraries are you using for threading etc.&lt;br /&gt;I 
	have some knowledge about this topic, but it&amp;#39;s very far from being profound. 
	Because of that I&amp;#39;m happy that&lt;br /&gt;there are some smart people in
	&lt;a href="http://msdn2.microsoft.com/en-us/concurrency/default.aspx"&gt;Parallel 
	Computing Developer Center&lt;/a&gt; who made an excellent extension&lt;br /&gt;for .NET -
	&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=e848dc1d-5be3-4941-8705-024bc7f180ba&amp;amp;displaylang=en"&gt;
	ParallelFX&lt;/a&gt;.&lt;/p&gt;
	
&lt;p&gt;There is a lot in it and there&amp;#39;s a lot interesting topics to write about, 
	but because this is my first post, I will start&lt;br /&gt;with something simple and 
	still very powerful. I will write only about &lt;i&gt;Do&lt;/i&gt; method. According 
	to documentation,&lt;br /&gt;it&amp;#39;s a method with following declaration:&lt;/p&gt;
	
&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;void&lt;/span&gt; &lt;span class="identifier"&gt;Do&lt;/span&gt;(&lt;br /&gt;	&lt;span class="keyword"&gt;params&lt;/span&gt; &lt;a href="http://msdn2.microsoft.com/en-us/bb534741" target="_blank"&gt;Action&lt;/a&gt;[] &lt;span class="parameter"&gt;actions&lt;/span&gt;&lt;br /&gt;)&lt;/pre&gt;
	
&lt;p&gt;This method &amp;quot;executes each of the provided actions inside a discrete, 
	asynchronous task&amp;quot;. It doesn&amp;#39;t&lt;br /&gt;finishes until &lt;b&gt;each&lt;/b&gt; 
	of provided actions has completed. That means, it will finish when the slowest 
	action finishes. Imagine&lt;br /&gt;that you have two long running methods called&lt;i&gt; 
	foo&lt;/i&gt; and&lt;i&gt; bar&lt;/i&gt;. If you call them in sequential manner you will 
	need to&lt;br /&gt;wait until&lt;i&gt; foo&lt;/i&gt; finishes its execution, then you will run&lt;i&gt; 
	bar&lt;/i&gt; method and wait until it finishes its execution. If you run&lt;br /&gt;them 
	in parallel you will only need to wait as much as the longest of this two is 
	executing. Let&amp;#39;s see an example. &lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    &lt;span class="cskeyword"&gt;class&lt;/span&gt; &lt;span class="csclass"&gt;Program&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="cskeyword"&gt;private static double&lt;/span&gt; x = 1000000000;&lt;br /&gt;&lt;br /&gt;        &lt;span class="cskeyword"&gt;private static void&lt;/span&gt; foo()&lt;br /&gt;        { &lt;span class="cskeyword"&gt;for&lt;/span&gt; (&lt;span class="cskeyword"&gt;double&lt;/span&gt; i = 0; i &amp;lt; x; i++) ;}&lt;br /&gt;&lt;br /&gt;        &lt;span class="cskeyword"&gt;private static void&lt;/span&gt; bar()&lt;br /&gt;        { &lt;span class="cskeyword"&gt;for&lt;/span&gt; (&lt;span class="cskeyword"&gt;double&lt;/span&gt; i = 0; i &amp;lt; x; i++) ;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span class="cskeyword"&gt;static void&lt;/span&gt; Main(&lt;span class="cskeyword"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="csclass"&gt;Stopwatch&lt;/span&gt; watch = &lt;span class="cskeyword"&gt;new&lt;/span&gt; &lt;span class="csclass"&gt;Stopwatch&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;            watch.Start();&lt;br /&gt;            &lt;span class="cscomment"&gt;// *** sequential&lt;/span&gt;&lt;br /&gt;            foo();&lt;br /&gt;            bar();&lt;br /&gt;            watch.Stop();&lt;br /&gt;            &lt;br /&gt;            &lt;span class="csclass"&gt;Console&lt;/span&gt;.WriteLine(&lt;span class="csstring"&gt;&amp;quot;Not parallel: &amp;quot;&lt;/span&gt; + &lt;br /&gt;                              (watch.ElapsedMilliseconds / 1000.0).ToString() + &lt;br /&gt;                              &lt;span class="csstring"&gt;&amp;quot;s&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            watch.Reset();&lt;br /&gt;            watch.Start();&lt;br /&gt;            &lt;span class="cscomment"&gt;// *** parallel&lt;/span&gt;&lt;br /&gt;            Parallel.Do(() =&amp;gt; foo(), () =&amp;gt; bar());&lt;br /&gt;            watch.Stop();&lt;br /&gt;            &lt;br /&gt;            &lt;span class="csclass"&gt;Console&lt;/span&gt;.WriteLine(&lt;span class="csstring"&gt;&amp;quot;Parallel: &amp;quot;&lt;/span&gt; + &lt;br /&gt;                              (watch.ElapsedMilliseconds / 1000.0).ToString() + &lt;br /&gt;                              &lt;span class="csstring"&gt;&amp;quot;s&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;
&lt;p&gt;The time which you get running the above program will depend about your 
computer CPU. On my computer&lt;br /&gt;(Core Duo, 2.33GHz) I get:&lt;br /&gt;
&lt;i&gt;Not parallel: 8,769s&lt;br /&gt;
Parallel: 4,595s&lt;br /&gt;
&lt;/i&gt;So, with a help of just one line of code &lt;b&gt;we have a multithreaded 
program&lt;/b&gt;! &lt;/p&gt;

&lt;p&gt;That&amp;#39;s all for the first time. It was just a little introduction. When I 
learn more about ParallelFX I will write again.&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=2077" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/ParallelFX/default.aspx">ParallelFX</category><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/concurrent+programming/default.aspx">concurrent programming</category></item><item><title>Inline text editing control in ASP.NET AJAX</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/02/25/inline-text-editing-control-in-asp-net-ajax.aspx</link><pubDate>Mon, 25 Feb 2008 09:23:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:2052</guid><dc:creator>boris.sevo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=2052</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/02/25/inline-text-editing-control-in-asp-net-ajax.aspx#comments</comments><description>&lt;p&gt;
&lt;img src="http://blogs.mscommunity.net/blogs/borissevo/blog-images/InlineEdit.gif" alt="Inline text editing" style="margin-left:10px;" align="right" /&gt;Inline text editing is a technique which I really like. It can be used on 
various places, displaying updatable widget title or displaying updateable user 
status are just two of them. Still, it can be very confusing to the users if they aren&amp;#39;t enough familiar with the application they are using. To make it more 
user friendly, I added few features (dynamic CSS changing, mouse cursor 
changing and tooltip) which purpose is to suggest the users that there is something 
more behind the plain text which is initially shown to them.&lt;br /&gt;
Control is implemented as 
&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.scriptcontrol.aspx"&gt;ScriptControl&lt;/a&gt; 
and all the logic behind it is made with JavaScript using 
&lt;a href="http://www.asp.net/ajax/"&gt;ASP.NET AJAX framework&lt;/a&gt; (&lt;b&gt;full source code&lt;/b&gt; and a test web page 
are provided at the end - 
you will need VS2008 to build it). It doesn&amp;#39;t extend any ASP.NET controls (&amp;quot;TextBox&amp;quot; 
and &amp;quot;Label&amp;quot; are generated on the fly) and it allows you to get and store updated 
text on the persistent medium (database for example) using .asmx web services.&lt;br /&gt;
In source code you can see how to:&lt;/p&gt;

&lt;ul&gt;
	
&lt;li&gt;build an ASP:NET AJAX control with embedded .js file&lt;/li&gt;
	
&lt;li&gt;use ASP.NET AJAX DOM extensions&lt;/li&gt;
	
&lt;li&gt;dynamically invoke web services to asynchronously communicate with the 
	server&lt;/li&gt;
	
&lt;li&gt;process various DOM events like keypress, mouseover, mouseout, click and 
	blur&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use this control you only need to add one line of code in your .aspx page.&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;&lt;font color="#a31515" size="2"&gt;&amp;lt;inlEdit:InlineEditing&lt;/font&gt; &lt;font color="#ff0000" size="2"&gt;ID&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;InlineEditing1&amp;quot;&lt;/font&gt; &lt;font color="#ff0000" size="2"&gt;runat&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;server&amp;quot;&lt;/font&gt; &lt;font color="#ff0000" size="2"&gt;TextId&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;100&amp;quot;&lt;/font&gt; &lt;br /&gt;&lt;font color="#ff0000" size="2"&gt;                       ServicePath&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;WebService.asmx&amp;quot;&lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;  GetMethod&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;Load&amp;quot; &lt;/font&gt;&lt;br /&gt;&lt;font color="#ff0000" size="2"&gt;                       SaveMethod&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;Save&amp;quot; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;CssClass&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;lblClass&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;                       LabelHoverCssClass&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;lblHoverClass&amp;quot;&lt;/font&gt; &lt;br /&gt;&lt;font color="#ff0000" size="2"&gt;                       TextBoxCssClass&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&amp;quot;txtbxCssClass&amp;quot;/&amp;gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;This is just a first version. Potential improvements are:&lt;/p&gt;

&lt;ul&gt;
	
&lt;li&gt;add a button next to &amp;quot;TextBox&amp;quot; do the same what pressing enter key does&lt;/li&gt;
	
&lt;li&gt;show progress indication when retrieving and updating text&lt;/li&gt;
	
&lt;li&gt;add MaxLength property (handle pasting and various keys)&lt;/li&gt;
	
&lt;li&gt;any other improvement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.mscommunity.net/blogs/borissevo/sources/inline-editing-src.zip"&gt;Source code&lt;/a&gt; (tested in IE7, FF2.0.0.12 and Opera 9.26.)&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=2052" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/ASP.NET+AJAX/default.aspx">ASP.NET AJAX</category></item><item><title>Using enter in TextBox control to submit the form with multiple Button controls</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2008/02/13/using-enter-in-textbox-control-to-submit-the-form-with-multiple-button-controls.aspx</link><pubDate>Wed, 13 Feb 2008 19:52:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:1902</guid><dc:creator>boris.sevo</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=1902</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2008/02/13/using-enter-in-textbox-control-to-submit-the-form-with-multiple-button-controls.aspx#comments</comments><description>
&lt;p&gt;Hitting enter after you have typed something in some TextBox control is something natural to most 
users, but it&lt;br /&gt;makes life of the ASP.NET developer more difficult. If you don&amp;#39;t know about 
what I&amp;#39;m talking here is a simple&lt;br /&gt;example. Imagine that you have a simple web form with 
two text fields and two button controls. The first text field&lt;br /&gt;and the first button are 
used for searching the web site and they are placed somewhere near the top of the page.&lt;br /&gt;The second text field and the second button 
are used for some totally different purpose and that&amp;#39;s filtering the&lt;br /&gt;entries 
displayed on the form. &lt;br /&gt;
The important thing to remember is that both buttons, when clicked, are causing postback 
and that first button is&lt;br /&gt;rendered before the second button. So, when enter is pressed inside 
the first text field, web site will be searched.&lt;br /&gt;So far so good.
But let&amp;#39;s suppose that 
user has typed something in the &lt;b&gt;second&lt;/b&gt; text field. If enter is pressed while&lt;br /&gt;mouse cursor is inside the second text field, user will expect that the form entries will 
be filtered. But that isn&amp;#39;t going&lt;br /&gt;to happen! The 
&lt;b&gt;first&lt;/b&gt; button will do the submit and web site will be searched once again.&lt;/p&gt;
 

&lt;p&gt;Described behavior I found in IE7 and Opera. Firefox is immune to this problem. To understand why is 
this happening&lt;br /&gt;we need to look at the code. Here is the code of the simple web form which will demonstrate 
the problem:&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    &amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;        ...&lt;br /&gt;        &amp;lt;script language=&amp;quot;javascript&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;            function Submit(id, e) {&lt;br /&gt;                var isEnter = window.event == null ? &lt;br /&gt;                              e.keyCode == 13 : &lt;br /&gt;                              window.event.keyCode == 13;&lt;br /&gt;                if(isEnter)&lt;br /&gt;                    document.getElementById(id).click();&lt;br /&gt;            }&lt;br /&gt;        &amp;lt;/script&amp;gt;&lt;br /&gt;        &amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;            protected void btnSearch_Click(object sender, EventArgs e)&lt;br /&gt;            { lit1.Text = &amp;quot;I&amp;#39;m searching&amp;quot;; }&lt;br /&gt;            &lt;br /&gt;            protected void filterBtn_Click(object sender, EventArgs e)&lt;br /&gt;            { lit1.Text = &amp;quot;I&amp;#39;m filtering&amp;quot;; }&lt;br /&gt;        &amp;lt;/script&amp;gt;&lt;br /&gt;    &amp;lt;/head&amp;gt;&lt;br /&gt;	&lt;br /&gt;	&lt;br /&gt;    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;asp:Literal ID=&amp;quot;lit1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Literal&amp;gt;&lt;br /&gt;        &amp;lt;br /&amp;gt;&lt;br /&gt;        &amp;lt;asp:TextBox ID=&amp;quot;TextBox1&amp;quot; runat=&amp;quot;server&amp;quot; 
                             onkeypress=&amp;quot;Submit(&amp;#39;btnSearch&amp;#39;, event)&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID=&amp;quot;btnSearch&amp;quot; runat=&amp;quot;server&amp;quot; 
                             onclick=&amp;quot;btnSearch_Click&amp;quot; Text=&amp;quot;Search&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;br /&amp;gt;&lt;br /&gt;        &amp;lt;asp:TextBox ID=&amp;quot;TextBox2&amp;quot; runat=&amp;quot;server&amp;quot; 
                             onkeypress=&amp;quot;Submit(&amp;#39;filterBtn&amp;#39;, event)&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID=&amp;quot;filterBtn&amp;quot; runat=&amp;quot;server&amp;quot; 
                             onclick=&amp;quot;filterBtn_Click&amp;quot; Text=&amp;quot;Filter&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;The interesting part isn&amp;#39;t the web form source code then the generated html. Here it is only the 
important part:&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    &amp;lt;input name=&amp;quot;TextBox1&amp;quot; type=&amp;quot;text&amp;quot; id=&amp;quot;TextBox1&amp;quot; 
              onkeypress=&amp;quot;Submit(&amp;#39;btnSearch&amp;#39;, event)&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;input &lt;b&gt;type=&amp;quot;submit&amp;quot;&lt;/b&gt; name=&amp;quot;btnSearch&amp;quot; value=&amp;quot;Search&amp;quot; id=&amp;quot;btnSearch&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;br /&amp;gt;&lt;br /&gt;    &amp;lt;input name=&amp;quot;TextBox2&amp;quot; type=&amp;quot;text&amp;quot; id=&amp;quot;TextBox2&amp;quot; 
              onkeypress=&amp;quot;Submit(&amp;#39;filterBtn&amp;#39;, event)&amp;quot; /&amp;gt;&lt;br /&gt;    &amp;lt;input &lt;b&gt;type=&amp;quot;submit&amp;quot;&lt;/b&gt; name=&amp;quot;filterBtn&amp;quot; value=&amp;quot;Filter&amp;quot; id=&amp;quot;filterBtn&amp;quot; /&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Both buttons are generated as submit buttons and that&amp;#39;s what is causing the problems. When you press 
enter while you&lt;br /&gt;are typing inside the second text field (TextBox2) default button will do the submit. 
Default button, if explicitly not&lt;br /&gt;specified, will be the first rendered button (in this case this is 
the btnSearch). You can change the default button by&lt;br /&gt;setting the form&amp;#39;s defaultbutton attribute to
id of some other button, but this won&amp;#39;t fix the problem. The solution is to say to&lt;br /&gt;ASP.NET 
that is shouldn&amp;#39;t render 
buttons which type is submit. Instead it should render regular buttons. We can do that&lt;br /&gt;with the help of 
&lt;b&gt;UseSubmitBehavior&lt;/b&gt; property. 
All we need to do is to set it to false. The markup will now look like this:&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    ...&lt;br /&gt;    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;        ...&lt;br /&gt;        &amp;lt;asp:TextBox ID=&amp;quot;TextBox1&amp;quot; runat=&amp;quot;server&amp;quot; 
                             onkeypress=&amp;quot;Submit(&amp;#39;btnSearch&amp;#39;, event)&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID=&amp;quot;btnSearch&amp;quot; runat=&amp;quot;server&amp;quot; onclick=&amp;quot;btnSearch_Click&amp;quot; &lt;br /&gt;         Text=&amp;quot;Search&amp;quot; &lt;b&gt;UseSubmitBehavior=&amp;quot;false&amp;quot;&lt;/b&gt; /&amp;gt;&lt;br /&gt;        &amp;lt;br /&amp;gt;&lt;br /&gt;        &amp;lt;asp:TextBox ID=&amp;quot;TextBox2&amp;quot; runat=&amp;quot;server&amp;quot; 
                             onkeypress=&amp;quot;Submit(&amp;#39;filterBtn&amp;#39;, event)&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Button ID=&amp;quot;filterBtn&amp;quot; runat=&amp;quot;server&amp;quot; onclick=&amp;quot;filterBtn_Click&amp;quot; &lt;br /&gt;         Text=&amp;quot;Filter&amp;quot; &lt;b&gt;UseSubmitBehavior=&amp;quot;false&amp;quot;&lt;/b&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Generated HTML now looks like this:&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    ...&lt;br /&gt;    &amp;lt;input &lt;b&gt;type=&amp;quot;button&amp;quot;&lt;/b&gt; name=&amp;quot;btnSearch&amp;quot; value=&amp;quot;Search&amp;quot; id=&amp;quot;btnSearch&amp;quot; &lt;br /&gt;     &lt;b&gt;onclick=&amp;quot;java_script:__doPostBack(&amp;#39;btnSearch&amp;#39;,&amp;#39;&amp;#39;)&amp;quot;&lt;/b&gt;/&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;    &amp;lt;input &lt;b&gt;type=&amp;quot;button&amp;quot;&lt;/b&gt; name=&amp;quot;filterBtn&amp;quot; value=&amp;quot;Filter&amp;quot; id=&amp;quot;filterBtn&amp;quot; &lt;br /&gt;     &lt;b&gt;onclick=&amp;quot;java_script:__doPostBack(&amp;#39;filterBtn&amp;#39;,&amp;#39;&amp;#39;)&amp;quot;&lt;/b&gt;/&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;That&amp;#39;s it. When you press enter inside TextBox1 btnSearch will do the submit, and if you press enter 
inside the TextBox2&lt;br /&gt;btnSearch will do the submit.&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=1902" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Internal DSLs, fluent interfaces and extension methods in C#</title><link>http://live.mscommunity.net/blogs/borissevo/archive/2007/12/21/internal-dsls-fluent-interfaces-and-extension-methods-in-c.aspx</link><pubDate>Thu, 20 Dec 2007 14:55:00 GMT</pubDate><guid isPermaLink="false">4a43ed64-1a24-4d7d-9bcd-c9f8b8acacd0:1273</guid><dc:creator>boris.sevo</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://live.mscommunity.net/blogs/borissevo/rsscomments.aspx?PostID=1273</wfw:commentRss><comments>http://live.mscommunity.net/blogs/borissevo/archive/2007/12/21/internal-dsls-fluent-interfaces-and-extension-methods-in-c.aspx#comments</comments><description>
&lt;p&gt;This is one of my longest blog posts and because of that I will start with a short list 
which describes what I will cover in this post:&lt;/p&gt;

&lt;ul&gt;
	
&lt;li&gt;internal DSLs&lt;/li&gt;
	
&lt;li&gt;fluent interfaces&lt;/li&gt;
	
&lt;li&gt;method chaining&lt;/li&gt;
	
&lt;li&gt;extension methods&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
Few weeks ago I found &lt;a href="http://nealford.com"&gt;Neal Ford&amp;#39;s&lt;/a&gt; 
session material about 
&lt;a href="http://nealford.com/downloads/conferences/canonical/Neal_Ford-Building_DSLs_in_Static_and_Dynamic_Languages-handouts.pdf"&gt;
Building DSLs in Static and Dynamic Languages&lt;/a&gt;. This is a material from one 
&lt;a href="http://www.nofluffjuststuff.com/index.jsp"&gt;No Fluff Just Stuff symposium&lt;/a&gt; - 
&lt;a href="http://www.nofluffjuststuff.com/conference/chicago/2007/11/index.html"&gt;
Great Lakes Software Symposium&lt;/a&gt; which is as far as I can see a really great conference with a tones 
of interesting sessions. (You can also found a lot of interesting materials at 
&lt;a href="http://nealford.com/mypastconferences.htm"&gt;Neal&amp;#39;s Conference Slides &amp;amp; Samples section&lt;/a&gt;.) 
&lt;/p&gt;

&lt;h3&gt;Internal DSLs and Fluent Interfaces&lt;/h3&gt;
&lt;p&gt;If you take a look at a NFJS web page you can see that they have a book called a NFJS anthology. 
Old copy (2006) of this book has a topic &lt;i&gt;DSLs and Language-Oriented Programming&lt;/i&gt; by Neal Ford. 
In this topic Neal wrote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A domain-specific language is a limited form of computer 
language designed for a specific class of problems. ... 
Two types of DSLs exist: internal and external. An internal DSL is a 
internal domain-specific language written &amp;quot;on top&amp;quot; of the underlying syntax of your 
base language. If Java is your base language, then an internal DSL written in Java 
uses Java syntax to define the language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(more info about DSLs: 
&lt;a href="http://martinfowler.com/bliki/DslReadings.html"&gt; Martin Fowler&amp;#39;s DSLReadings&lt;/a&gt;) &lt;/p&gt;

&lt;p&gt;&lt;b&gt;External&lt;/b&gt; DSLs were clear to me before, because sometimes when you are faced with a problem from 
a specific domain, building a whole new language can really help you to express this problem. If you 
are building an external DSL you are building a language with a syntax which is diffrent then your base 
language syntax. Hence, you need to build a lexer and parser for your external DSL. &lt;br /&gt;
But, the purpose of &lt;b&gt;internal&lt;/b&gt; DSLs wasn&amp;#39;t so clear to me. I was asking myself why on hell 
would I like to build another language &amp;quot;on top&amp;quot; of my base language? Well, the answer lies in 
something which is called &lt;b&gt;fluent interface&lt;/b&gt; 
(&lt;a href="http://martinfowler.com/bliki/FluentInterface.html"&gt;Martin Fowler&amp;#39;s original bliki entry coining the term&lt;/a&gt;).  The term fluent interface and internal DSL are in many ways synonyms. The whole concept can be 
reduced to a single sentence from a Martin Fowler&amp;#39;s text:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The API is primarily designed to be readable and to flow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So when you are designing an API to be fluent you are building a code which 
intent is to look like a well-formed sentences. The best way to describe this is probably by example. 
Imagaine that you have a following two classes:
&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    public class Appointment&lt;br /&gt;    {&lt;br /&gt;        private string _name;&lt;br /&gt;        private DateTime _startTime;&lt;br /&gt;        private DateTime _endTime;&lt;br /&gt;&lt;br /&gt;        public string Name&lt;br /&gt;        {&lt;br /&gt;            get { return this._name; }&lt;br /&gt;            set { this._name = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public DateTime StartTime&lt;br /&gt;        {&lt;br /&gt;            get { return this._startTime; }&lt;br /&gt;            set { this._startTime = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public DateTime EndTime&lt;br /&gt;        {&lt;br /&gt;            get { return this._endTime; }&lt;br /&gt;            set { this._endTime = value; }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public class AppointmentCalender&lt;br /&gt;    {&lt;br /&gt;        private List&amp;lt;Appointment&amp;gt; _apponitments;&lt;br /&gt;&lt;br /&gt;        public AppointmentCalender()&lt;br /&gt;        { _apponitments = new List&amp;lt;Appointment&amp;gt;(); }&lt;br /&gt;&lt;br /&gt;        public void Add(Appointment app)&lt;br /&gt;        { _apponitments.Add(app); }&lt;br /&gt;&lt;br /&gt;        public string Print()&lt;br /&gt;        { ... }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;If we want to remember that we have a dentist in 5 days from 4PM to 6PM in 
non-fluent way we will probably do something like this:
&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;	//&amp;quot;dentist&amp;quot; in 5 days from 4PM to 6PM&lt;br /&gt;        AppointmentCalender appCalender = &lt;br /&gt;		new AppointmentCalender();&lt;br /&gt;&lt;br /&gt;        Appointment app1 = new Appointment();&lt;br /&gt;        DateTime dt1 = new DateTime(DateTime.Now.Year,&lt;br /&gt;                                    DateTime.Now.Month,&lt;br /&gt;                                    DateTime.Now.Day + 5,&lt;br /&gt;                                    16, 0, 0);&lt;br /&gt;        app1.Name = &amp;quot;dentist&amp;quot;;&lt;br /&gt;        app1.StartTime = dt1;&lt;br /&gt;        app1.EndTime = dt1.AddHours(2);&lt;br /&gt;        appCalender.Add(app1);&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;Or if you think that this setters are requiring to much work you can write appropriate 
constructor and then you have something like this:
&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;	DateTime dt1 = new DateTime(DateTime.Now.Year,&lt;br /&gt;                                    DateTime.Now.Month,&lt;br /&gt;                                    DateTime.Now.Day + 5,&lt;br /&gt;                                    16, 0, 0);&lt;br /&gt;	appCalender.Add(new Appointment(&amp;quot;dentist&amp;quot;, dt1, dt1.AddHours(2)));&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;Although the second example is conciser then the first one, initialization of dentist&amp;#39;s start termine is 
still extremely ugly. The constructor saved us from some work but without a deeper look at constructor&amp;#39;s 
implementation it&amp;#39;s hard to say what is the meaning and purpose of all its parameters. In first example 
we didn&amp;#39;t have this problem because from setter&amp;#39;s names (Name, StartTime and EndTime) it was clear what 
exactly the code is doing. From above two examples we can see that we have two candidates which need to be 
more fluent. First we will make initialization of the DataTime object more fluent and then we will do the 
same with the initialization of the Appointment object.&lt;/p&gt;

&lt;h3&gt;How to make your API more fluent?&lt;/h3&gt;
&lt;p&gt;Before C# 3.0 was introduced if you want to make your API more fluent you were limited to the 
&lt;b&gt;method chaining&lt;/b&gt;. In method chaining you are making the modifier methods return the host object 
so that multiple modifiers can be invoked in a single expression. Although, this is something which can 
help you a lot while building the fluent interface, it is also bringing one bad habit in your 
API about which you can read more in the next section. In C# 3.0 there is a new concept 
called &lt;b&gt;extension methods&lt;/b&gt;. There is many info about extension methods on a web and if you 
don&amp;#39;t know what they are you can find more info about them on Scott Guthrie&amp;#39;s blog post 
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx"&gt;New &amp;quot;Orcas&amp;quot; Language Feature: Extension Methods&lt;/a&gt;. 
Here I will just give a short definition from this 
Scott Guthrie&amp;#39;s post:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Extension methods allow developers to add new methods to the public contract of an existing 
CLR type, without having to sub-class it or recompile the original type.  Extension Methods help blend 
the flexibility of &amp;quot;duck typing&amp;quot; support popular within dynamic languages today with the performance 
and compile-time validation of strongly-typed languages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For us, extension methods are specially usefull because they can help us make 
DataTime more fluent. We can accomplish this by extending DateTime CLR type with few methods. Here is the 
code which is doing exactly that: 
&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    public static class DataTimeExtMethods&lt;br /&gt;    {&lt;br /&gt;        public static TimeSpan days(this int number)&lt;br /&gt;        {&lt;br /&gt;            return new TimeSpan(number, 0, 0, 0);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static DateTime fromToday(this TimeSpan ts)&lt;br /&gt;        {&lt;br /&gt;            DateTime dt = new DateTime(DateTime.Now.Year, &lt;br /&gt;				       DateTime.Now.Month, &lt;br /&gt;				       DateTime.Now.Day);&lt;br /&gt;            return dt.Add(ts);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static DateTime at(this DateTime dt, int hour)&lt;br /&gt;        {&lt;br /&gt;            return new DateTime(dt.Year, dt.Month, dt.Day, hour, 0, 0);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static int pm(this int hour)&lt;br /&gt;        {&lt;br /&gt;            if (hour &amp;gt; 0 &amp;amp;&amp;amp; hour &amp;lt; 13)&lt;br /&gt;                return hour + 12;&lt;br /&gt;            else&lt;br /&gt;                throw new ArgumentException(&amp;quot;Wrong hour value&amp;quot;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;Now we can write something like this:&lt;/p&gt;

&lt;pre&gt;	DateTime dt = 5.days().fromToday().at(4.pm());&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Writing &lt;i&gt;5.days().fromToday()&lt;/i&gt; before extension methods were introduced, were impossible because 
there was no way to extend a value type like integer. This kind of syntax is something natural to 
dynamic-typed languages so in Groovy it is possible to write &lt;i&gt;5.days.fromoday.at(4.pm)&lt;/i&gt;. 
Because the use of extension methods isn&amp;#39;t limited to value types only, we can also extend Appointment class 
with them. Nevertheless let&amp;#39;s see how we can make Appointement class more fluent with a help of 
method chaining.
&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;    public class Appointment&lt;br /&gt;    {&lt;br /&gt;        ...&lt;br /&gt;&lt;br /&gt;        public Appointment Having(string name)&lt;br /&gt;        {&lt;br /&gt;            this.Name = name;&lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public Appointment From(DateTime date)&lt;br /&gt;        {&lt;br /&gt;            this.StartTime = date;&lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public Appointment To(DateTime date)&lt;br /&gt;        {&lt;br /&gt;            this.EndTime = date;&lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public Appointment At(DateTime date)&lt;br /&gt;        {&lt;br /&gt;            this.StartTime = this.EndTime = date;&lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;Now if we have a dentist in 5 days from 4PM to 6PM and birthday party in 17 days we can write:&lt;/p&gt;

&lt;pre style="border:1px dashed;padding:3px 0px;"&gt;	AppointmentCalender appCalender = new AppointmentCalender();&lt;br /&gt;	&lt;br /&gt;	//fluent way&lt;br /&gt;	DateTime dt = 5.days().fromToday().at(4.pm());&lt;br /&gt;        appCalender.Add(new Appointment().Having(&amp;quot;dentist&amp;quot;).&lt;br /&gt;                                          From(dt).&lt;br /&gt;                                          To(dt.AddHours(2)));&lt;br /&gt;					  &lt;br /&gt;        appCalender.Add(new Appointment().Having(&amp;quot;birthday party&amp;quot;).&lt;br /&gt;                                          At(17.days().fromToday()));&lt;br /&gt;&lt;/pre&gt;
&lt;h3&gt;Pros and cons&lt;/h3&gt;
&lt;p&gt;As we can see from above examples fluent interfaces can make your code more 
human readable. The price of this readability is more effort in API construction. The simple (&amp;quot;primitive&amp;quot;) 
API of constructors, setters and additional methods is easier to write but harder to read. Better 
readability isn&amp;#39;t worth the effort in all cases. In my opinion there are two places were better 
readability is worth the effort in time and thinking and that are library and framework construction.&lt;/p&gt;

&lt;p&gt;Effort in time and thinking isn&amp;#39;t the only negative side in building fluent APIs. In method chaining 
we are using modifier methods which are returning the object which they modify although the common 
convention is that modifier methods are void
(&lt;a href="http://martinfowler.com/bliki/CommandQuerySeparation.html"&gt;Command query separation&lt;/a&gt;). 
The use of extension methods is also bringing some potential 
problems. To ensure that you can&amp;#39;t hijack or subvert the intended behavior of existing methods CLR will 
always prefer an instance method over an extension method. Although this is a good thing it also causes one 
problem known as 
&lt;a href="http://dotnet.agilekiwi.com/blog/2006/04/extension-methods-problem.html"&gt;versioning problem&lt;/a&gt;.&lt;/p&gt;
&lt;img src="http://live.mscommunity.net/aggbug.aspx?PostID=1273" width="1" height="1"&gt;</description><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/DSL/default.aspx">DSL</category><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/C_2300_+3.0/default.aspx">C# 3.0</category><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/extension+methods/default.aspx">extension methods</category><category domain="http://live.mscommunity.net/blogs/borissevo/archive/tags/programming+concepts/default.aspx">programming concepts</category></item></channel></rss>