<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3758391117135674795</id><updated>2011-07-07T23:15:44.775-07:00</updated><category term='C#'/><category term='practice'/><category term='jquery'/><category term='Globalization'/><category term='MVC'/><category term='publish'/><category term='WCF'/><category term='Data-binding'/><category term='Faulted Service Channel'/><category term='GridView'/><category term='UI'/><category term='.net'/><category term='ListBox'/><category term='Routing'/><category term='TextBox'/><category term='using'/><category term='Event'/><category term='validation'/><category term='ASP.NET'/><category term='FormView'/><title type='text'>Cullen's Code Reveries</title><subtitle type='html'>Sharing the joy of learning on Asp.Net MVC, TDD/BDD, DDD and anything code related.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-7847959858829356715</id><published>2011-04-23T17:58:00.000-07:00</published><updated>2011-04-23T17:58:45.065-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='validation'/><title type='text'>Validation: set maxlength of a text box using MVC validation</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Given a view model as below:&lt;/span&gt;&lt;br /&gt;&lt;pre style="font-family: consolas; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;EmployeeFormViewModel&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;   [&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;&lt;span style="color: #2b91af;"&gt;Required&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;(ErrorMessage&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;&lt;span style="color: #a31515;"&gt;"*"&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;)]&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;pre style="font-family: consolas; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;    [&lt;span style="color: #2b91af;"&gt;StringLength&lt;/span&gt;(20,ErrorMessage&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Max length&amp;nbsp;20&amp;nbsp;characters"&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: blue;"&gt;    public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;Name&amp;nbsp;{&amp;nbsp;&lt;span style="color: blue;"&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span style="color: blue;"&gt;set&lt;/span&gt;;&amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;div style="font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; white-space: normal;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: consolas; white-space: pre;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;And when client validation and unobtrusive JavaScript are&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;enabled&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;in a MVC 3 app in web.config in the root directory:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;appSettings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red;"&gt;key&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;ClientValidationEnabled&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red;"&gt;value&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red;"&gt;key&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;UnobtrusiveJavaScriptEnabled&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red;"&gt;value&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #a31515;"&gt;appSettings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;A view:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;h2&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;Employee&amp;nbsp;Form&lt;span style="color: blue;"&gt;&lt;span style="color: maroon;"&gt;h2&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-attachment: initial; background-clip: initial; background-color: yellow; background-image: initial; background-origin: initial;"&gt;@&lt;/span&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt;&amp;nbsp;(Html.BeginForm(&lt;span style="color: #a31515;"&gt;"Employee&lt;span class="Apple-style-span" style="color: black;"&gt;&lt;span style="color: #a31515;"&gt;"&lt;/span&gt;,&lt;span style="color: #a31515;"&gt;"SaveEmployeeForm"&lt;/span&gt;,&lt;span style="color: #a31515;"&gt;"Home"&lt;/span&gt;,&lt;span style="color: #2b91af;"&gt;FormMethod&lt;/span&gt;.Post))&lt;/span&gt;&lt;/span&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background-attachment: initial; background-clip: initial; background-color: yellow; background-image: initial; background-origin: initial;"&gt;@&lt;/span&gt;Html.TextBoxFor(model=&amp;gt;model.Name)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;input&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"submit"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;value&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Submit"&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;renders into Html on the client side:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;form&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;action&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"/SaveEmployeeForm/Home?Length=4"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;method&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"post"&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;input&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;data-val&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"true"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: red;"&gt;data-val-length&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Name&amp;nbsp;must&amp;nbsp;not&amp;nbsp;be&amp;nbsp;longer&amp;nbsp;than&amp;nbsp;20&amp;nbsp;characters&amp;nbsp;long"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  &lt;b&gt;&lt;span style="color: red;"&gt;data-val-length-max&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"20"&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: red;"&gt;data-val-required&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"*"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: red;"&gt;id&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Name"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Name"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"text"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;  &lt;span style="color: red;"&gt;value&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;""&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;input&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"submit"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;value&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Submit"&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&lt;span style="color: maroon;"&gt;form&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small; white-space: normal;"&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This works great: it shows the error message when the user types a name longer than 20&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;characters and leaves the text box.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;But it still allows the user to type in more than 20 letters before the focus leaves the text box.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;What if I want to keep the user from keying in 20 characters?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Well, the&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;maxlength attribute of the&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;input tag is the answer. &amp;nbsp;When it is set to 20, the user is only allowed to type in 20 characters. &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I really don't want to keep setting "maxlength" to every single text box that I create and more importantly I want validation attribute "StringLength" to control this value. &amp;nbsp;But the generated code does not set the "maxlength" attribute. &amp;nbsp;How do I set the value of maxlength attribute using the value of data-val-length-max attribute?&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;div style="font-family: 'Times New Roman';"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;A little JQuery sweetness does the trick:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: black; font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small; white-space: normal;"&gt;&lt;pre style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: consolas; font-size: x-small;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;script&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;language&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"javascript"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(document).ready&lt;br /&gt;&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;span style="color: blue;"&gt;function&lt;/span&gt;&amp;nbsp;()&amp;nbsp;{&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;$(&lt;span style="color: maroon;"&gt;'input[data-val-length-max]'&lt;/span&gt;).each&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;(&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;span style="color: blue;"&gt;function&lt;/span&gt;&amp;nbsp;(index)&amp;nbsp;{&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(&lt;span style="color: blue;"&gt;this&lt;/span&gt;).attr(&lt;span style="color: maroon;"&gt;'maxlength'&lt;/span&gt;,&amp;nbsp;$(&lt;span style="color: blue;"&gt;this&lt;/span&gt;).attr(&lt;span style="color: maroon;"&gt;'data-val-length-max'&lt;/span&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;})&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&lt;span style="color: blue;"&gt;&lt;span style="color: maroon;"&gt;script&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;/span&gt;&lt;pre style="color: blue; font-family: consolas; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: Verdana, sans-serif; white-space: normal;"&gt;What the code above says is that for every input tag with the attribute of "data-val-length-max", use the value of it to set the value of "maxlength" attribute.&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/span&gt;&lt;pre style="color: blue; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-7847959858829356715?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/7847959858829356715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/validation-set-maxlength-of-text-box.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/7847959858829356715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/7847959858829356715'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/validation-set-maxlength-of-text-box.html' title='Validation: set maxlength of a text box using MVC validation'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-7467533489296671787</id><published>2011-04-22T15:45:00.000-07:00</published><updated>2011-04-22T15:45:39.997-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='practice'/><title type='text'>Double Meaning or Entendre</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Double Meaning or &lt;a href="http://en.wikipedia.org/wiki/Double_entendre"&gt;Double Entendre&lt;/a&gt;&amp;nbsp;can be very funny when used in jokes. &amp;nbsp;Read the following jokes from &lt;a href="http://www.ucalegon.com/double.php"&gt;this site&lt;/a&gt;:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #ebecfb;"&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Old Timer 1 : You know what I miss?&lt;br /&gt;Old Timer 2 : And what might that be?&lt;br /&gt;Old Timer 1 : Really small targets that are miles away.&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #ebecfb;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #ebecfb;"&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;Teacher 1 : You know what makes me mad?&lt;br /&gt;Teacher 2 : What?&lt;br /&gt;Teacher 1 : Changing the 'e' to an 'a' and adding a 'd'.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;Ha-ha-ha, he-he-he, wasn't that funny!&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;In the first example&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;above&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;, "miss" could mean thinking of something sentimental wishing you still have it or could mean when I shoot a target I don't hit it. &amp;nbsp;Same thing in the second one where "me" could me myself or the word "me". &amp;nbsp;This is all funny and silly until you start coding that way.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;During a recent design session, a team member&amp;nbsp;suggested reusing existing properties for different purposes. &amp;nbsp;This reminded me of a story I heard s&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;ome years back, during another design session, &amp;nbsp;a team discovered &amp;nbsp;that they needed a new field in the database for their application. &amp;nbsp;The app had been released and it was in production at a major client's site. &amp;nbsp;The client operated on 24/7 schedule, taking down the database would mean longer downtime therefore losing money. &amp;nbsp;So the team decided to use an existing field but use it differently depending the format of the value in the field. &amp;nbsp;It sounded like a good solution, all they had to do is re-deploy the application which took less then 5 minutes. &amp;nbsp;The client gets new features without much of downtime. &amp;nbsp;Great news, right? &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;To the client, yes. &amp;nbsp;How about for the developers and the long term maintenance of the application? &amp;nbsp;Subsequently, the property of the class that the field was mapped to had to be handled differently. Wherever the property was used, a helper extension method was used to parse the value so the new value is can be put to work while making sure not to break the old code. &amp;nbsp;Suddenly, we created a lot of work for ourselves which meant higher cost to develop the feature. &amp;nbsp;More importantly, it had a long term implication for maintenance. &amp;nbsp;As we know people change jobs, developers come and go, now there was additional cost for maintenance because we had to document what the field really meant so we could educate new developers to use it properly. &amp;nbsp;In the end, it&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;really&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;wasn't worth saving the client's downtime of maybe 10 hours the most.&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;The moral of the story: do not give double meaning to a property, field. &amp;nbsp;Do it properly using &lt;a href="http://lostechies.com/wp-content/uploads/2011/03/pablos_solid_ebook.pdf"&gt;S.O.L.I.D &lt;/a&gt;principles.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #0c343d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-7467533489296671787?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/7467533489296671787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/double-meaning-or-entendre.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/7467533489296671787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/7467533489296671787'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/double-meaning-or-entendre.html' title='Double Meaning or Entendre'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-412629762866989322</id><published>2011-04-17T14:10:00.000-07:00</published><updated>2011-04-17T14:10:02.974-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Globalization'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>A mystery solved</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;Today, I was trying to solve a problem where on our French site, a specification number (which is a decimal number) of the same product &amp;nbsp;was toggling between 1.3 and 1,3&amp;nbsp;intermittently. &amp;nbsp;It should be 1,3 for French. &amp;nbsp;It turned out the problem was in two folds.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;First of all, the following code is being used to convert decimal to string:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;//specNumber = 1.3;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;specNumber.ToString();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;Secondly, the app is running on two load balanced servers. &amp;nbsp;One server's region and language is set up as:&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-P6ujwrJV6fU/TapI0dU8eDI/AAAAAAAAADE/KRtMzB2AO74/s1600/Region+and+Language+-+English.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-P6ujwrJV6fU/TapI0dU8eDI/AAAAAAAAADE/KRtMzB2AO74/s400/Region+and+Language+-+English.png" width="346" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;while the other is set up as below:&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-qFiaTEMZ1Ro/TapI0_aUo2I/AAAAAAAAADI/DFqYZ93nZgc/s1600/Region+and+Language+-+French.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://2.bp.blogspot.com/-qFiaTEMZ1Ro/TapI0_aUo2I/AAAAAAAAADI/DFqYZ93nZgc/s400/Region+and+Language+-+French.png" width="345" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;That explains why the value is appearing as 1.3 or 1,3 intermittently.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;To address this problem, we need to fix it in code. &amp;nbsp;When the site is being browsed in French we'll use:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;   &lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;fr&amp;nbsp;=&amp;nbsp;&lt;span style="color: #2b91af;"&gt;CultureInfo&lt;/span&gt;.CreateSpecificCulture(&lt;span style="color: #a31515;"&gt;"fr-CA"&lt;/span&gt;);&lt;br /&gt;   specNumber.ToString(fr.NumberFormat);&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;That way, the code is not dependent on the server region and language settings.&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-412629762866989322?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/412629762866989322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/mystery-solved.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/412629762866989322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/412629762866989322'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/mystery-solved.html' title='A mystery solved'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-P6ujwrJV6fU/TapI0dU8eDI/AAAAAAAAADE/KRtMzB2AO74/s72-c/Region+and+Language+-+English.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-2144514730690482038</id><published>2011-04-13T20:39:00.000-07:00</published><updated>2011-04-13T20:39:01.224-07:00</updated><title type='text'>Asp.net View (Webform View) to Razor View Translator</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;If you need to have asp.net views translated to Razor views, you might be interested in checking out Teleriks&amp;nbsp;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;a href="https://github.com/telerik/razor-converter"&gt;Razor Converter&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-2144514730690482038?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/2144514730690482038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/aspnet-view-webform-view-to-razor-view.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/2144514730690482038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/2144514730690482038'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/aspnet-view-webform-view-to-razor-view.html' title='Asp.net View (Webform View) to Razor View Translator'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-8118220008808124885</id><published>2011-04-12T06:20:00.000-07:00</published><updated>2011-04-12T06:20:47.234-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Routing'/><category scheme='http://www.blogger.com/atom/ns#' term='MVC'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Custom Routing in MVC</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In MVC, by default, out of the box routing pattern is {controller}/{action}/{id} where id is optional as defined in the Global.asax.cs:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: consolas;"&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;routes.MapRoute&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;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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Default"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: green;"&gt;//&amp;nbsp;Route&amp;nbsp;name&lt;/span&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #a31515;"&gt;"{controller}/{action}/{id}"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: green;"&gt;//&amp;nbsp;URL&amp;nbsp;with&amp;nbsp;parameters&lt;/span&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;{controller&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Home"&lt;/span&gt;,&amp;nbsp;action&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Index"&lt;/span&gt;,&amp;nbsp;id&amp;nbsp;=&amp;nbsp;&lt;span style="color: #2b91af;"&gt;UrlParameter&lt;/span&gt;.Optional}&amp;nbsp;&lt;span style="color: green;"&gt;//&amp;nbsp;Parameter&amp;nbsp;defaults&lt;/span&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;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;However, this will not always meet your needs. &amp;nbsp;In such case, you can create custom routes. &amp;nbsp;For instance, let's say it is a requirement that the "HR (Human Resource)" &amp;nbsp;department of your company should have their own unique URL in a pattern like this: "Hr/PersonalProfile/Display/1234". &amp;nbsp;Custom route can be utilized to make this work:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: consolas; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&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;routes.MapRoute&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;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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Hr"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: green;"&gt;//&amp;nbsp;The name must be unique in a route table&lt;/span&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Hr/PersonalProfile/{action}/{id}"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: green;"&gt;//&amp;nbsp;URL&amp;nbsp;with&amp;nbsp;parameters&lt;/span&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;{controller&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"PersonalProfile&lt;span class="Apple-style-span" style="color: black;"&gt;&lt;span style="color: #a31515;"&gt;"&lt;/span&gt;,&amp;nbsp;action&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Display"&lt;/span&gt;,&amp;nbsp;id&amp;nbsp;=&amp;nbsp;&lt;span style="color: #2b91af;"&gt;UrlParameter&lt;/span&gt;.Optional}&amp;nbsp;&lt;span style="color: green;"&gt;//&amp;nbsp;Parameter&amp;nbsp;defaults&lt;/span&gt;&lt;/span&gt;&lt;/span&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;/pre&gt;&lt;pre style="font-family: consolas; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div&gt;Now you can display a personal profile using this URL: http://{yourdomian}/Hr/PersonalProfile/Display/1234&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="background-color: #ffe599; color: #990000;"&gt;One very important thing to note is that MVC tries to find matching route in the order of the routes registration.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In our example, the custom route "Hr" must be registered before the default route is. &amp;nbsp;Otherwise, when the site is accessed with the URL "http://{yourdomian}/Hr/PersonalProfile/Display/1234", it matches the default route and it will try to look for a controller named "Hr" which doesn't exist. &amp;nbsp;This, of course, results in an error as below:&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;h1&gt;Server Error in '/' Application.&lt;hr color="silver" size="1" width="100%" /&gt;&lt;/h1&gt;&lt;h2&gt;&lt;i&gt;The resource cannot be found.&lt;/i&gt; &lt;/h2&gt;&lt;/span&gt;&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;b&gt;Description: &lt;/b&gt;HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. &amp;nbsp;Please review the following URL and make sure that it is spelled correctly. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Requested URL: &lt;/b&gt;/Hr/PersonalProfile/Display&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;Phil Haack created a very useful tool for debugging MVC routing: &lt;a href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx"&gt;route debugger&lt;/a&gt; and you can get it through NuGet package management tool. &amp;nbsp;Just type in the following command in Package Manager Console:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;pre style="font-family: consolas;"&gt;PM&amp;gt;&amp;nbsp;install-package&amp;nbsp;routedebugger&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;If you're not familiar with NuGet, &lt;a href="http://haacked.com/archive/2010/10/06/introducing-nupack-package-manager.aspx"&gt;read about it here&lt;/a&gt;. &amp;nbsp;And &lt;a href="http://nuget.codeplex.com/"&gt;download it from here.&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-8118220008808124885?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/8118220008808124885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/custom-routing-in-mvc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8118220008808124885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8118220008808124885'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2011/04/custom-routing-in-mvc.html' title='Custom Routing in MVC'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-4947614050994813474</id><published>2011-03-22T06:02:00.000-07:00</published><updated>2011-03-22T06:02:40.040-07:00</updated><title type='text'>Hide MVC version # and Asp.Net version # from HTTP Header</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;By default, Asp.Net and Mvc emit the version numbers in the HTTP header as below:&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;a href="https://lh3.googleusercontent.com/-ZArgyVttbwo/TYiXEv1QoUI/AAAAAAAAACo/mI1c0A1ttpI/s1600/Response+Header.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="128" src="https://lh3.googleusercontent.com/-ZArgyVttbwo/TYiXEv1QoUI/AAAAAAAAACo/mI1c0A1ttpI/s400/Response+Header.PNG" width="400" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;In the figure above, &lt;b&gt;X-AspNet-Version&lt;/b&gt; is the Asp.net version and&amp;nbsp;&lt;b&gt;X-AspNetMvc-Version&lt;/b&gt; is version number of&amp;nbsp;System.Web.Mvc version number as shown below:&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;a href="https://lh6.googleusercontent.com/-LyfZBE046U0/TYiW7jkz0GI/AAAAAAAAACk/AYy_pT8BT2Y/s1600/Response+Header+Mvc+Version.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="332" src="https://lh6.googleusercontent.com/-LyfZBE046U0/TYiW7jkz0GI/AAAAAAAAACk/AYy_pT8BT2Y/s400/Response+Header+Mvc+Version.PNG" width="400" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;But for some reason that you don't want the world know that you're running your app on Asp.net and MVC, you can turn them off.&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;To remove&amp;nbsp;&amp;nbsp;X-AspNet-Version from the header, set the value of&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red; font-family: consolas; white-space: pre;"&gt;enableVersionHeader of httpRuntime tag &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;to false the web.config as follows:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;pre style="font-family: consolas; line-height: normal;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;system.web&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;httpRuntime&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red;"&gt;enableVersionHeader&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;nbsp;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas; line-height: normal;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: consolas; line-height: normal;"&gt;To remove&lt;/span&gt;&lt;span style="color: blue; font-family: consolas; line-height: normal;"&gt; &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;X-AspNetMvc-Version from the header, you can modify the application_start event in&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; white-space: normal;"&gt;Global.asax.cs a&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; white-space: normal;"&gt;s follows:&lt;/span&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;&lt;pre style="font-family: consolas;"&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Application_Start()&lt;br /&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;MvcHandler&lt;/span&gt;.DisableMvcResponseHeader&amp;nbsp;=&amp;nbsp;&lt;span style="color: blue;"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;After making above changes in my app, the end result of the header looks like this:&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-F4d2iJdhcAs/TYidSXcEY3I/AAAAAAAAACs/RF_qyDOJjzA/s1600/Response+Header+After.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="127" src="https://lh6.googleusercontent.com/-F4d2iJdhcAs/TYidSXcEY3I/AAAAAAAAACs/RF_qyDOJjzA/s400/Response+Header+After.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;pre style="font-family: consolas;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-4947614050994813474?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/4947614050994813474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2011/03/hide-mvc-version-and-aspnet-version.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/4947614050994813474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/4947614050994813474'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2011/03/hide-mvc-version-and-aspnet-version.html' title='Hide MVC version # and Asp.Net version # from HTTP Header'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='https://lh3.googleusercontent.com/-ZArgyVttbwo/TYiXEv1QoUI/AAAAAAAAACo/mI1c0A1ttpI/s72-c/Response+Header.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-930374308195162289</id><published>2010-09-13T06:28:00.000-07:00</published><updated>2010-09-13T06:29:25.008-07:00</updated><title type='text'>NTLDR is missing Press CTRL+ALT+DEL to restart on Windows XP Pro SP3</title><content type='html'>Saturday, decided to defragment my old laptop since I didn't remember when it was the last time that was done. &amp;nbsp;My laptop runs on Window XP professional with SP3. As I looked at the analysis graph, it was indeed heavily fragmented. &amp;nbsp;I left the laptop alone while defragmenting. &amp;nbsp;Couple hours later, I shut it down. &amp;nbsp;The next time when I booted it up, I got the following error message:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 16px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 16px;"&gt;NTLDR is missing&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 16px;"&gt;&lt;br style="-webkit-box-sizing: border-box;" /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 16px;"&gt;Press CTRL+ALT+DEL to restart.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 16px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;And the system would not boot &lt;sigh&gt;. &amp;nbsp;I searched the web for solutions and found a bunch of posts on that topic. &amp;nbsp;Some of them are risky (could damage the hard disk partitions) while others require a floppy drive which my laptop doesn't have. &amp;nbsp;After much thinking and praying, the solution was quite simple:&lt;/sigh&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Load the XP Pro OS CD/DVD into the drive&lt;/li&gt;&lt;li&gt;Reboot the laptop and press F12 (this could be different depending on your laptop manufacturer) to load boot devices option&lt;/li&gt;&lt;li&gt;Select to boot from CD/DVD drive&lt;/li&gt;&lt;li&gt;The OS installation will start but don't panic it's not going to overwrite anything yet&lt;/li&gt;&lt;li&gt;When options are presented to install, repair or quit installation, choose 'R' for repair&lt;/li&gt;&lt;li&gt;And then select the OS you want load. &amp;nbsp;By default you'll see: 1. c:\windows. &amp;nbsp;In this case, type "1" and press enter&lt;/li&gt;&lt;li&gt;And then put the admin password&lt;/li&gt;&lt;li&gt;After you've logged in, you'll be presented with command prompt C:\Windows&lt;/li&gt;&lt;li&gt;Type D: plush Enter&lt;/li&gt;&lt;li&gt;Copy file NTLDR from the OS drive to root C:&lt;/li&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;copy d:\i386\ntldr c:\.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;li&gt;Reboot the computer&lt;/li&gt;&lt;li&gt;It should reboot correctly&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Hope this will work for you as well. &amp;nbsp;Naturally, if your cause is different, this will not work for you.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-930374308195162289?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/930374308195162289/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2010/09/ntldr-is-missing-press-ctrlaltdel-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/930374308195162289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/930374308195162289'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2010/09/ntldr-is-missing-press-ctrlaltdel-to.html' title='NTLDR is missing Press CTRL+ALT+DEL to restart on Windows XP Pro SP3'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-1117951531373252808</id><published>2010-09-01T10:32:00.000-07:00</published><updated>2010-09-01T10:32:28.407-07:00</updated><title type='text'>Some MVC Resources</title><content type='html'>&lt;a href="http://elegantcode.com/2010/07/05/asp-net-mvc-my-personal-view-rules/"&gt;View Rules&lt;/a&gt;: this is a great post on ElegantCode.com regarding MVC view rules;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-1117951531373252808?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/1117951531373252808/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2010/09/some-mvc-resources.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/1117951531373252808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/1117951531373252808'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2010/09/some-mvc-resources.html' title='Some MVC Resources'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-9121010754324472745</id><published>2010-08-31T07:10:00.000-07:00</published><updated>2010-08-31T07:11:59.870-07:00</updated><title type='text'>When to use and when not use Asynchronous actions</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Mvc 2 has a really cool feature: asynchronous actions. &amp;nbsp;You can implement actions so it can be called asynchronously and your route is the same as synchronous call when making the request. &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Just read and article on &lt;a href="http://msdn.microsoft.com/en-us/library/ee728598%28v=VS.100%29.aspx"&gt;msdn&lt;/a&gt;&amp;nbsp;when to use asynchronous actions and when not to:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;When to use&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;the operations in the actions are network-bound or I/O bound&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Parallelism is more important than simplicity of code&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You want to provide a mechanism to allow users to cancel long-running request&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;When not to use&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;operations a CPU bound&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;operations are simple and short-running&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-9121010754324472745?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/9121010754324472745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2010/08/when-to-use-and-when-not-use.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/9121010754324472745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/9121010754324472745'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2010/08/when-to-use-and-when-not-use.html' title='When to use and when not use Asynchronous actions'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-7122773072282400077</id><published>2010-08-30T12:05:00.000-07:00</published><updated>2010-08-31T06:59:13.536-07:00</updated><title type='text'>Organizing View Models with Namespaces</title><content type='html'>In Asp.Net MVC, each view should, preferably,&amp;nbsp;have a strongly typed view model. &amp;nbsp;For a given controller, it could serve up multiple views through actions or simply by rendering partial views. &amp;nbsp;Sometimes using same view model name for different views make sense while the view model implementations are quite different. &amp;nbsp;For instance, I might have a view model named ProductForm for a view named Index as follows&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ProductModel&lt;br /&gt;{&lt;br /&gt;  [DisplayName(&lt;span class="str"&gt;"Product Id"&lt;/span&gt;)]&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; Guid Id { get; set; }&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Category { get; set; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;and I also have a view model for a view named Edit:&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ProductModel&lt;br /&gt;{&lt;br /&gt;  [DisplayName(&lt;span class="str"&gt;"Product Id"&lt;/span&gt;)]&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; Guid Id { get; set; }&lt;br /&gt;  [Requried]&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;br /&gt;  [Requried]&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; Category Category { get; set; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; Category&lt;br /&gt;{&lt;br /&gt;   Hardware,&lt;br /&gt;   Software,&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;The difference between the two models are obvious. &amp;nbsp;In this case, to distinguish the two models, I could use different names for each or separate them using name space. &amp;nbsp;I find it easier to use namespace the models and it also follows the pattern convention which Mvc uses to locate a view for a controller as follows:&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Models&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;|---Home (controller name)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; |--- Index (view name)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|--- ProductModel.cs (view model)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;div style="font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; |--- Edit (view name)&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|--- Product&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Model&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;.cs (view model)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"&gt;So the name space looks like as follows:&lt;/span&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;UI.Home.Index.ProductModel&lt;br /&gt;UI.Home.Edit.ProductModel&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-7122773072282400077?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/7122773072282400077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2010/08/view-model-structures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/7122773072282400077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/7122773072282400077'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2010/08/view-model-structures.html' title='Organizing View Models with Namespaces'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-8489136617518867785</id><published>2009-08-11T10:19:00.000-07:00</published><updated>2009-08-11T11:05:59.056-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Faulted Service Channel'/><category scheme='http://www.blogger.com/atom/ns#' term='using'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='publish'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>using statement causes undesired result in WCF client.</title><content type='html'>I have a WCF service client which is a WinForms desktop application.  I have a method that is responsible for uploading certain information by consuming the WCF service.  I was initializing the proxy as follows:&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;using ( proxy = new WCFServiceClient. WCFServiceClient() ) {&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;proxy = new WCFServiceClient. WCFServiceClient() ;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;proxy.UploadInfo();&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It was working just fine.  Then I had to make some changes (added a new method to the business logic layer called by the service) on the server side, it compiled without any error and passed the unit test.  So I published it to my test site and ran a unit test against the test site.  To my surprise, I started getting the following error message: &lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 102);"&gt;The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;After bit of searching, I found this &lt;a href="http://msdn.microsoft.com/en-us/library/aa355056.aspx"&gt;article&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;According to this artical, one "&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;should not use the C# "using" statement to automatically clean up resources when using a typed client&lt;/span&gt;".  The reason being, "&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;The C# "using" statement results in a call to &lt;/span&gt;&lt;strong&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;Dispose&lt;/span&gt;&lt;/strong&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;(). This is the same as &lt;/span&gt;&lt;strong&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;Close&lt;/span&gt;&lt;/strong&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;(), which may throw exceptions when a network error occurs. Because the call to &lt;/span&gt;&lt;strong&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;Dispose&lt;/span&gt;&lt;/strong&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;() happens implicitly at the closing brace of the "using" block, this source of exceptions is likely to go unnoticed both by people writing the code and reading the code. This represents a potential source of application errors&lt;/span&gt;."  That was exactly what was going on with my code.  The "using" statement was masking the actual error that was occurring on the server.  After removing the "using" statement and running the test again, I got the actual error which was the service couldn't find the new method that I had just added.  It turned out that the publishing tool didn't update the business logic DLLs.  The problem went away after forcing a replacement of the BLL DLLs.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-8489136617518867785?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/8489136617518867785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/08/using-statement-causes-undesired-result.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8489136617518867785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8489136617518867785'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/08/using-statement-causes-undesired-result.html' title='using statement causes undesired result in WCF client.'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-2509638903930509807</id><published>2009-08-04T16:29:00.000-07:00</published><updated>2009-08-04T16:46:04.600-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='GridView'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Display Grid Page info ("Page # of Total Page Count")</title><content type='html'>The GridView control has the options to enable paging.  You can also specify different paging modes (NextPreviousFirstLast, Numeric, etc.) but it does not provide a way to display page info in the format of "Page 1 of 10" when you're in the mode of NextPriviousFirstLast mode.  So I decided to add my own.  Below the GridView control, I added a label control as follows:&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;asp:label id="lblNumberOfRecords" runat="server" visible="False"&gt;&lt;/asp:Label&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I don't like to hard code strings into code if I can avoid it for internationlization reasons and for ease of editing at one place.  So I put all my messages in a resource file.   To display "Page # of #", I create a string resource named "PageNumberOfTotal" and its content is "Page {0} of {1}".  Then I handle the DataBound event of the GridView control as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;        protected void gdRecords_DataBound(object sender, EventArgs e)&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;//If there are records to display, then display the message&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            if (gdRecords.Rows.Count &gt; 0)&lt;/div&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                lblNumberOfRecords.Visible = true;&lt;/div&gt;&lt;div&gt;                lblNumberOfRecords.Text = string.Format(&lt;/div&gt;&lt;div&gt;                   MessageResource.Properties.Resources.PageNumberOfTotal,&lt;/div&gt;&lt;div&gt;                    gdRecords.PageIndex + 1,&lt;/div&gt;&lt;div&gt;                    gdRecords.PageCount);&lt;/div&gt;&lt;div&gt;            } //If there isn't any records to display, the hide the label control&lt;/div&gt;&lt;div&gt;            else lblNumberOfRecords.Visible = false;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-2509638903930509807?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/2509638903930509807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/08/display-grid-page-info-page-of-total.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/2509638903930509807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/2509638903930509807'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/08/display-grid-page-info-page-of-total.html' title='Display Grid Page info (&quot;Page # of Total Page Count&quot;)'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-3633834907302580537</id><published>2009-07-23T13:00:00.000-07:00</published><updated>2009-07-23T13:11:32.557-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FormView'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Populating controls in FormView Insert or Empty empty template with default values</title><content type='html'>FormView doesn't make it easy for a developer when he wants to populate the controls in a empty or insert template with default values.  After doing some search, I found out one way to accomplish this is to override ItemCreated event as follows:&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;        protected void fvMine_ItemCreated(object sender, EventArgs e)&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;//if the current mode in insert mode&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;              if (fvMine.CurrentMode == FormViewMode.Insert)&lt;/div&gt;&lt;div&gt;              {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;//get a reference to the control&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;                            txt = (TextBox) fvMine.Row.FindControl("txtCity");&lt;/div&gt;&lt;div&gt;                            if (txt != null)&lt;/div&gt;&lt;div&gt;                            {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;    &lt;/span&gt;// populate it with a default value&lt;br /&gt;&lt;/div&gt;&lt;div&gt;                                txt.Text = "New York";&lt;/div&gt;&lt;div&gt;                            }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-3633834907302580537?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/3633834907302580537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/populating-controls-in-formview-insert.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/3633834907302580537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/3633834907302580537'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/populating-controls-in-formview-insert.html' title='Populating controls in FormView Insert or Empty empty template with default values'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-6700792168610553031</id><published>2009-07-20T12:30:00.000-07:00</published><updated>2009-07-20T12:52:10.263-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TextBox'/><category scheme='http://www.blogger.com/atom/ns#' term='Event'/><category scheme='http://www.blogger.com/atom/ns#' term='UI'/><title type='text'>Delayed TextBox TextChanged event</title><content type='html'>I have a textbox that does a search upon TextChanged event firing.  However, I don't want it search for every character the users types unless the user is done with typing.  So I wanted to delay it from firing.  I found a great article &lt;a href="http://www.codeproject.com/KB/miscctrl/CustomTextBox.aspx?display=PrintAll"&gt;here &lt;/a&gt;that describes exactly what I wanted.  It uses System.Timers.Timer but I changed it to System.Windows.Forms.Timer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-6700792168610553031?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/6700792168610553031/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/delayed-textbox-textchanged-event.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/6700792168610553031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/6700792168610553031'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/delayed-textbox-textchanged-event.html' title='Delayed TextBox TextChanged event'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-6577764547821880577</id><published>2009-07-20T10:14:00.000-07:00</published><updated>2009-07-20T10:16:54.444-07:00</updated><title type='text'>WCF Send/Receive Progress Update</title><content type='html'>After searching around the web, I didn't find any satifactory article.  So posted a &lt;a href="http://stackoverflow.com/questions/1154403/wcf-intercept-message-send-receive-progress-in-client"&gt;question&lt;/a&gt; on &lt;a href="http://stackoverflow.com"&gt;StackOverflow.com&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-6577764547821880577?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/6577764547821880577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/wcf-sendreceive-progress-update.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/6577764547821880577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/6577764547821880577'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/wcf-sendreceive-progress-update.html' title='WCF Send/Receive Progress Update'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-921287723134760425</id><published>2009-07-20T08:16:00.000-07:00</published><updated>2009-07-20T08:20:20.826-07:00</updated><title type='text'>WCF Message Send/Receive Progress</title><content type='html'>I've been working a project that involves sending/receiving messages to a server from a desktop application via a WCF webservice.  When transferring a large chunk of message, I'd like to display a progress indicator to the desktop user.  I'm going to do a little bit of research to find such a solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-921287723134760425?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/921287723134760425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/wcf-message-sendreceive-progress.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/921287723134760425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/921287723134760425'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/07/wcf-message-sendreceive-progress.html' title='WCF Message Send/Receive Progress'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-8729811744723121640</id><published>2009-06-02T12:20:00.000-07:00</published><updated>2009-06-03T08:09:58.258-07:00</updated><title type='text'>Debugging WCF: Unable to automatically step into the server. The remote procedure could not be debugged.</title><content type='html'>I kept getting the following error all of a sudden when I was debugging a WCF client: &lt;strong&gt;"Unable to automatically step into the server. The remote procedure could not be debugged." &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The WCF service is hosted by IIS. The client is a WinForm application. Both projects reside within the same solution. When I received the error message, I checked to make sure that the WCF service host's web.config has the debug flag set to true as follows: &lt;span style="color:#ff0000;"&gt;&amp;lt;compilation debug="true"&amp;gt;&lt;/span&gt;. But I was still getting the same error. Then it dawned on me that I had changed the binding from wsHttp to wsDualHttp and wonder it that was the cause. So I reverted it back to wsHttp binding and I was able to step through the serive code when debugging the client.&lt;br /&gt;&lt;br /&gt;I'll have to look up why that is when I get a chance from my project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-8729811744723121640?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/8729811744723121640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/06/debugging-wcf-unable-to-automatically.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8729811744723121640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8729811744723121640'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/06/debugging-wcf-unable-to-automatically.html' title='Debugging WCF: Unable to automatically step into the server. The remote procedure could not be debugged.'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-5325252841577044095</id><published>2009-04-15T12:13:00.000-07:00</published><updated>2009-04-15T12:42:39.089-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data-binding'/><category scheme='http://www.blogger.com/atom/ns#' term='ListBox'/><category scheme='http://www.blogger.com/atom/ns#' term='FormView'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Move selection to the next item in ListBox when the record is deleted in a FormView</title><content type='html'>In &lt;a href="http://sharpercoder.blogspot.com/2009/04/highlight-objectdatasource-bound.html"&gt;my previous post&lt;/a&gt;, I showed the method to highlight a newly inserted record from the FormView in the ListBox.  Conversly, when a record is deleted from the FormView, I'd like to move to the next item in the ListBox if there is one.  If the deleted item is last item, then move to the previous one.&lt;br /&gt;&lt;br /&gt;Below is the definition of the ListBox: &lt;br /&gt;&amp;lt;asp:ListBox ID="listBoxEmployees" runat="server"&lt;br /&gt;    AutoPostBack="true" &lt;br /&gt;    DataSourceID="odsListBoxEmployees"&lt;br /&gt;    DataTextField="EmployeeName"&lt;br /&gt;    DataValueField="EmployeeID"&lt;br /&gt;    onselectedindexchanged="listBoxEmployees_SelectedIndexChanged" &lt;br /&gt;    ondatabound="listBoxEmployees_DataBound"&amp;gt;&lt;br /&gt;&amp;lt;/asp:ListBox&amp;gt;&lt;br /&gt;&lt;br /&gt;Below is the definition of the FormView:&lt;br /&gt;&amp;lt;asp:FormView &lt;br /&gt;    ID="fvEmployee"&lt;br /&gt;    runat="server"&lt;br /&gt;    DataKeyNames="EmployeeID"&lt;br /&gt;    DataSourceID="odsEmployee" &lt;br /&gt;    oniteminserted="fvEmployee_ItemInserted" &lt;br /&gt; &amp;gt;&lt;br /&gt;&lt;br /&gt;Below is the definition of the Object Data Source:&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:ObjectDataSource &lt;br /&gt;    ID="odsEmployee" &lt;br /&gt;    runat="server"&lt;br /&gt;    TypeName="Employees"&lt;br /&gt;    SelectMethod="SelectOne"&lt;br /&gt;    InsertMethod = "Insert"&lt;br /&gt;    UpdateMethod = "Update"&lt;br /&gt;    DeleteMethod = "Delete"&lt;br /&gt;    ConflictDetection="OverwriteChanges" &lt;br /&gt;    oninserted="odsEmployee_Inserted" &lt;br /&gt;    ondeleting="odsEmployee_Deleting"&lt;br /&gt;    &amp;gt;&lt;br /&gt;    &amp;lt;SelectParameters&amp;gt;&lt;br /&gt;        &amp;lt;asp:ControlParameter Name="EmployeeID" Type="Int32" Direction="Input" ControlID="listBoxEmployees" PropertyName="SelectedValue" /&amp;gt;&lt;br /&gt;    &amp;lt;/SelectParameters&amp;gt;&lt;br /&gt;    &amp;lt;InsertParameters&amp;gt;&lt;br /&gt;        &amp;lt;asp:Parameter Name="EmployeeName" Size="80" Direction = "Input" Type="String" /&amp;gt;&lt;br /&gt;    &amp;lt;/InsertParameters&amp;gt;&lt;br /&gt;    &amp;lt;UpdateParameters&amp;gt;&lt;br /&gt;        &amp;lt;asp:Parameter Name="EmployeeID" Type="Int32" Direction="Input" /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Parameter Name="EmployeeName" Size="80" Direction = "Input" Type="String" /&amp;gt;&lt;br /&gt;    &amp;lt;/UpdateParameters&amp;gt;&lt;br /&gt;&amp;lt;/asp:ObjectDataSource&amp;gt;&lt;br /&gt;&lt;br /&gt;Handle Deleted event of the ODS so before the record is deleted in the FormView, we'll store the next item in the ListBox in view state as follows:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected void odsEmployee_Deleting(object sender, ObjectDataSourceMethodEventArgs e)&lt;br /&gt;{&lt;br /&gt;    //if there are more one items in the list&lt;br /&gt;    if (listBoxEmployees.Items.Count &gt; 1)&lt;br /&gt;        //if the record to be deleted is not the last one in the list&lt;br /&gt;        if (listBoxEmployees.SelectedIndex &lt; listBoxEmployees.Items.Count-1)&lt;br /&gt;        {&lt;br /&gt;            //store the next item's value&lt;br /&gt;            ViewState["EmployeeID"] = listBoxEmployees.Items[++listBoxEmployees.SelectedIndex].Value;&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;            //if it is the last one, then store the previous item's value &lt;br /&gt;            ViewState["EmployeeID"] = listBoxEmployees.Items[--listBoxEmployees.SelectedIndex].Value;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The code above is self explanatory.&lt;br /&gt;&lt;br /&gt;Next handle the DataBound event of the ListBox control as follows:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected void listBoxEmployees_DataBound(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;if (listBoxEmployees.Items.Count &gt; 0)&lt;br /&gt;if (ViewState["EmployeeID"] != null)&lt;br /&gt;{&lt;br /&gt;listBoxEmployees.SelectedValue = ViewState["EmployeeID"].ToString();&lt;br /&gt;}&lt;br /&gt;else listBoxEmployees.SelectedIndex = 0;&lt;br /&gt;ViewState.Remove("EmployeeID");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This will set the SelectedValue of the ListBox to the value in the view state. After we used the value in the view state, we remove it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-5325252841577044095?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/5325252841577044095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/04/move-selection-to-next-item-in-listbox.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/5325252841577044095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/5325252841577044095'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/04/move-selection-to-next-item-in-listbox.html' title='Move selection to the next item in ListBox when the record is deleted in a FormView'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-8244889144766844763</id><published>2009-04-15T10:37:00.000-07:00</published><updated>2009-04-15T12:39:10.846-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data-binding'/><category scheme='http://www.blogger.com/atom/ns#' term='ListBox'/><category scheme='http://www.blogger.com/atom/ns#' term='FormView'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Highlight ObjectDataSource bound ListBox after ObjectDataSource bound FormView inserted a brand new record</title><content type='html'>I have a ListBox (I'll call it listBoxEmployees) that is bound to an ObjectDataSource (I'll call odsListBoxEmployees). &lt;br /&gt;&lt;br /&gt;&amp;lt;asp:ListBox ID="listBoxEmployees" runat="server"&lt;br /&gt;    AutoPostBack="true" &lt;br /&gt;    DataSourceID="odsListBoxEmployees"&lt;br /&gt;    DataTextField="EmployeeName"&lt;br /&gt;    DataValueField="EmployeeID"&lt;br /&gt;    onselectedindexchanged="listBoxEmployees_SelectedIndexChanged" &lt;br /&gt;    ondatabound="listBoxEmployees_DataBound"&amp;gt;&lt;br /&gt;&amp;lt;/asp:ListBox&amp;gt;&lt;br /&gt;&lt;br /&gt;It displays Employee Name as Text and stores EmployeeID as Value in the list.&lt;br /&gt;&lt;br /&gt;Then I have a FormView which is bound to another ObjectDataSource (I'll call it odsEmployee) which retrieves an individual record when an item is selected in the ListBox control.  Below is the FormView definition:&lt;br /&gt;&amp;lt;asp:FormView &lt;br /&gt;    ID="fvEmployee"&lt;br /&gt;    runat="server"&lt;br /&gt;    DataKeyNames="EmployeeID"&lt;br /&gt;    DataSourceID="odsEmployee" &lt;br /&gt; &amp;gt;&lt;br /&gt;&lt;br /&gt;Below is the ODS definition:&lt;br /&gt;&amp;lt;asp:ObjectDataSource &lt;br /&gt;    ID="odsEmployee" &lt;br /&gt;    runat="server"&lt;br /&gt;    TypeName="Employees"&lt;br /&gt;    SelectMethod="SelectOne"&lt;br /&gt;    InsertMethod = "Insert"&lt;br /&gt;    UpdateMethod = "Update"&lt;br /&gt;    DeleteMethod = "Delete"&lt;br /&gt;    ConflictDetection="OverwriteChanges" &lt;br /&gt;    oninserted="odsEmployee_Inserted" &lt;br /&gt;    ondeleting="odsEmployee_Deleting"&lt;br /&gt;    &amp;gt;&lt;br /&gt;    &amp;lt;SelectParameters&amp;gt;&lt;br /&gt;        &amp;lt;asp:ControlParameter Name="EmployeeID" Type="Int32" Direction="Input" ControlID="listBoxEmployees" PropertyName="SelectedValue" /&amp;gt;&lt;br /&gt;    &amp;lt;/SelectParameters&amp;gt;&lt;br /&gt;    &amp;lt;InsertParameters&amp;gt;&lt;br /&gt;        &amp;lt;asp:Parameter Name="EmployeeName" Size="80" Direction = "Input" Type="String" /&amp;gt;&lt;br /&gt;    &amp;lt;/InsertParameters&amp;gt;&lt;br /&gt;    &amp;lt;UpdateParameters&amp;gt;&lt;br /&gt;        &amp;lt;asp:Parameter Name="EmployeeID" Type="Int32" Direction="Input" /&amp;gt;&lt;br /&gt;        &amp;lt;asp:Parameter Name="EmployeeName" Size="80" Direction = "Input" Type="String" /&amp;gt;&lt;br /&gt;    &amp;lt;/UpdateParameters&amp;gt;&lt;br /&gt;&amp;lt;/asp:ObjectDataSource&amp;gt;&lt;br /&gt;&lt;br /&gt;What I want to do after inserting a record from the FormView is to add the newly inserted record in the ListBox control and highlight it by making it the selected item.  Below is how to achieve this:&lt;br /&gt;&lt;br /&gt;Handle the Inserted event of odsForm as follows:&lt;br /&gt;&lt;br /&gt;        protected void odsForm_Inserted(object sender, ObjectDataSourceStatusEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            ViewState["EmployeeID"] = e.ReturnValue;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;This will store the employee id of the new inserted record in the view state.&lt;br /&gt;&lt;br /&gt;And then handle the DataBound event of the ListBox as follows:&lt;br /&gt;&lt;br /&gt;        protected void listBoxEmployees_DataBound(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            if (listBoxEmployees.Items.Count &gt; 0)&lt;br /&gt;            if (ViewState["EmployeeID"] != null)&lt;br /&gt;            {&lt;br /&gt;                listBoxEmployees.SelectedValue = ViewState["EmployeeID"].ToString();&lt;br /&gt;            }&lt;br /&gt;            else listBoxEmployees.SelectedIndex = 0;&lt;br /&gt;            ViewState.Remove("EmployeeID");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;This will set the SelectedValue of the ListBox to the value in the view state.  After we used the value in the view state, we remove it.&lt;br /&gt;&lt;br /&gt;It works great.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-8244889144766844763?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/8244889144766844763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/04/highlight-objectdatasource-bound.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8244889144766844763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/8244889144766844763'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/04/highlight-objectdatasource-bound.html' title='Highlight ObjectDataSource bound ListBox after ObjectDataSource bound FormView inserted a brand new record'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-1386851538693683277</id><published>2009-04-15T07:30:00.000-07:00</published><updated>2009-04-15T07:40:43.702-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data-binding'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>The difference between Eval and Bind data binding functions in ASP.NET</title><content type='html'>When binding in ASP.NET within FormView, GridView or DetailsView, one could use data-binding expressions with this tag &lt;%# %&gt;.  There are two functions, which are Eval and Bind, used frequently.  For instance, suppose you a data source has the field named "ProductName", you could bind it as follows:&lt;br /&gt;&lt;br /&gt;&lt;%# Eval('ProductName')%&gt; OR &lt;%# Bind('ProductName')%&gt;&lt;br /&gt;&lt;br /&gt;So what is the difference between the two functions?&lt;br /&gt;The difference is, according to &lt;a href="http://msdn.microsoft.com/en-us/library/ms178366.aspx"&gt;MSDN&lt;/a&gt;, the &lt;span&gt;&lt;span class="input"&gt;Eval&lt;/span&gt;&lt;/span&gt; function is used to define one-way (read-only) binding. The &lt;span&gt;&lt;span class="input"&gt;Bind&lt;/span&gt;&lt;/span&gt; function is used for two-way (updatable) binding.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-1386851538693683277?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/1386851538693683277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/04/difference-between-eval-and-bind-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/1386851538693683277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/1386851538693683277'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/04/difference-between-eval-and-bind-data.html' title='The difference between Eval and Bind data binding functions in ASP.NET'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3758391117135674795.post-6081895685420019081</id><published>2009-02-19T13:26:00.000-08:00</published><updated>2009-04-15T12:04:49.071-07:00</updated><title type='text'>Hello, world!</title><content type='html'>This blog spot will serve as my development knowledge diary as well as a place where I share what I've learned so it may benefit those who are searching for knowledge in software development in Windows, .NET, MS SQL and C# stack.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3758391117135674795-6081895685420019081?l=sharpercoder.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sharpercoder.blogspot.com/feeds/6081895685420019081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sharpercoder.blogspot.com/2009/02/hello-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/6081895685420019081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3758391117135674795/posts/default/6081895685420019081'/><link rel='alternate' type='text/html' href='http://sharpercoder.blogspot.com/2009/02/hello-world.html' title='Hello, world!'/><author><name>Sr. Software Engineer/Architect</name><uri>http://www.blogger.com/profile/08327131385625856733</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
