<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Scott Hunter</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/scothu/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/scothu/feed.xml</link>
    <description>ASP.NET and .NET Musings</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:47:51 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>HTML 5 Updates for .NET 4</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/html-5-updates-for-net-4</link>
      <pubDate>Wed, 10 Aug 2011 22:49:41 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2011/08/10/html-5-updates-for-net-4/</guid>
      <description><![CDATA[After we shipped .NET 4 we began working on the next version of the framework and one of the things...]]></description>
      <content:encoded><![CDATA[<p>After we shipped .NET 4 we began working on the next version of the framework and one of the things that we have worked on for the next version of the framework is more support for HTML 5. We think that HTML 5 is so important that we have taken many of updates from the next framework and provided some of the most important ones as part of updates to .NET 4. This enables our customers to more easily develop HTML 5 applications now instead of waiting for the next framework. I’m going to highlight a couple of the updates and the major fixes they provide.</p>  <p><strong><u>Update for the .NET Framework 4</u></strong></p>  <p>The first update was shipped with VS 2010 SP1. You can read about the framework update here: <a title="https://support.microsoft.com/kb/2468871" href="https://support.microsoft.com/kb/2468871">https://support.microsoft.com/kb/2468871</a>. One of the features of HTML 5 is there are now new input types such as date, url, email and more. While most browsers today don’t support these new input types you should still use them today because most mobile devices do support them and it changes the keyboard these devices display. For example specifying type=”email” will cause many phones to provide the “@” character on the keyboard. type=”email” or type=”url” will cause many phones to provide the “.com” button on the keyboard as a shortcut.</p>  <p>Before the update above it was illegal to use these input types in Web Forms. The following would generate an error:</p>  <p>&lt;asp:TextBox id=”TextBoxEmail” runat=”server” type=”email” /&gt;</p>  <p>Because we were validating what values could be provided for the type= attribute. This validation was relaxed as part of the above update.</p>  <p><strong><u>Reliability Update 1 for the .NET Framework 4</u></strong></p>  <p>Earlier this week on patch Tuesday another update was released called the reliability update 1 for .NET 4: <a title="https://support.microsoft.com/kb/2533523" href="https://support.microsoft.com/kb/2533523">https://support.microsoft.com/kb/2533523</a>. This update solves a variety of problems with HTML 5 input types. If you used any of the HTML 5 input types (a few mentioned above) with server controls they would not behave properly in the following cases:</p>  <p><strong>UpdatePanel</strong> – The values of any HTML 5 input types would not be posted back on postback.</p>  <p><strong>Validation Controls</strong>&#160; - The ASP.NET validation controls such as asp:RequiredFieldValidator would not provide client validation on HTML 5 input types.</p>  <p><strong>Callbacks</strong> – ASP.NET pages that are using callbacks would not post back the values of any HTML 5 input types.</p>  <p>All of these items were corrected with the second update listed above. Even more support for HTML 5 will be coming in the next version of the framework and we hope to start announcing details around that soon. Note the above two updates also fix quite a few other things in .NET 4 as well so I suggest you read the details from the links.</p>]]></content:encoded>
    </item>
    <item>
      <title>Update on the Microsoft jQuery Plugins</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/update-on-the-microsoft-jquery-plugins</link>
      <pubDate>Fri, 15 Apr 2011 09:42:55 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2011/04/15/update-on-the-microsoft-jquery-plugins/</guid>
      <description><![CDATA[A little over a six months ago we blogged about the work that Microsoft was doing with jQuery...]]></description>
      <content:encoded><![CDATA[<p>A little over a six months ago we <a href="https://weblogs.asp.net/scottgu/archive/2010/10/04/jquery-templates-data-link-and-globalization-accepted-as-official-jquery-plugins.aspx">blogged</a> about the work that Microsoft was doing with jQuery plugins (jQuery Templates, Globalization, and Data Link). This post provides a little more information on the current status and on the plans for those plugins.</p>  <p>Over the past six months, as the jQuery and Microsoft teams have worked on the plugins, we've decided together that the richness and power of these plugins makes it important to develop them in the context of a strong relationship with a collaborative sub-team within jQuery. </p>  <p>To facilitate this, the jQuery team has announced some changes in the way plugins are managed. Each plugin will now be owned by a sub-team within the jQuery Project, such as the jQuery UI team or the jQuery Core Dev team.</p>  <p>When jQuery 1.5 shipped earlier this year, you might have wondered why jQuery Templates was not part of that release. The jQuery announcement clarifies this -- jQuery Templates is a key part of jQuery functionality, but it will nonetheless continue as a separate plugin in jQuery UI rather than shipping as part of jQuery Core. </p>  <p>This is a continuation of the investment that Microsoft is making in jQuery and jQuery UI. Our investment isn't limited to the plugins I just mentioned. For example, another important investment has been the new jQuery UI Grid project that we've provided support for at many levels. We're now shipping both jQuery and jQuery UI in our newer products, and we plan to have great support in ASP.NET for developers who want to use the jQuery UI Grid in their projects.</p>  <p>Moving forward, we'll continue to be involved in the design and development of jQuery Templates. This includes our contributions to the grid project, since the jQuery UI Grid is using the jQuery Templates plugin. Microsoft will also continue to work on Data Linking and its integration with jQuery Templates. We'll move that work to its own <a href="https://github.com/BorisMoore/jsviews">source repository</a>, plus we'll take ownership of the documentation.</p>  <p>We think these changes are a valuable step towards helping the Microsoft and jQuery teams and the community to move these plugins towards RTM quality and to ship them as great V1 products!</p>]]></content:encoded>
    </item>
    <item>
      <title>Updates to the Microsoft CDN (Updated 12/1/2010)</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/updates-to-the-microsoft-cdn-updated-1212010</link>
      <pubDate>Tue, 16 Nov 2010 09:36:00 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2010/11/16/updates-to-the-microsoft-cdn-updated-1212010/</guid>
      <description><![CDATA[I want to announce a couple of changes we have made to the Microsoft CDN recently.
Updated...]]></description>
      <content:encoded><![CDATA[<p>I want to announce a couple of changes we have made to the Microsoft CDN recently.</p>
<p><strong>Updated jQuery</strong></p>
<p>We have added both jQuery 1..4.3 and jQuery 1.4.4 to the CDN,&nbsp; plus there are vsdoc files for both of these releases. These new releases are available with these URLs:</p>
<p>jQuery version 1.4.4</p>
<p>&nbsp;</p>
<ul>
<li>
<div align="left"><a href="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js">https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js</a> </div>
</li>
<li>
<div align="left"><a href="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js">https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js</a> </div>
</li>
<li>
<div align="left"><a href="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4-vsdoc.js">https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4-vsdoc.js</a></div>
</li>
</ul>
<p>jQuery version 1.4.3</p>
<p>&nbsp;</p>
<ul>
<li><a href="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.3.js">https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.3.js</a> </li>
<li><a href="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.3.min.js">https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.3.min.js</a> </li>
<li><a href="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.3-vsdoc.js">https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.3-vsdoc.js</a></li>
</ul>
<p><strong>New Domain Name</strong></p>
<p>The Microsoft CDN is now available from a new domain name: ajax.aspnetcdn.com. We added support for this new domain name to increase the performance of the CDN. The primary benefit of the new domain is that it is not the microsoft.com domain, any requests to the microsoft.com cause the browser to send cookies for that domain across the wire. Since many people may have visited a Microsoft web property this means extra information is coming across the wire for those requests potentially slowing down the request. The new domain is a domain a user would never have visited in their browser and thus requests will have no additional payload. Testing has shown that this can increase speeds by up to 20%.</p>
<p>The previous domain ajax.microsoft.com is still available and will always remain available so all links to it will continue to function as usual but going forward we recommend people use the new domain.</p>
<p>Full details of the Microsoft CDN are available here: <a href="https://www.asp.net/ajaxlibrary/cdn.ashx" title="https://www.asp.net/ajaxlibrary/cdn.ashx">https://www.asp.net/ajaxlibrary/cdn.ashx</a></p>
<p><strong>SSL Support (12/1/2010)</strong></p>
<p>When we first created the new CDN ajax.aspnetcdn.com it did not support SSL (https://) style requests. As of 12/1/2010 the CDN has been updated to support SSL as well now.</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Web Pages Beta 2–Request Validation</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/web-pages-beta-2request-validation</link>
      <pubDate>Wed, 06 Oct 2010 22:09:02 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2010/10/06/web-pages-beta-2request-validation/</guid>
      <description><![CDATA[Today we released all kinds of goodness at Microsoft for ASP.NET developers:     - Web Pages Beta 2...]]></description>
      <content:encoded><![CDATA[<p>Today we released all kinds of goodness at Microsoft for ASP.NET developers:</p>  <ul>   <li>- Web Pages Beta 2 – An update to our new support for adding simple Razor syntax pages to to web applications. </li>    <li>- MVC 3 Beta – An update to our preview release from a few months ago with several enhancements around razor, helpers, unobtrusive javascript, dependency injection and more. </li>    <li>- NuPack – Package manager for finding, adding, upgrading libraries for your .NET projects. This makes it super easy to find libraries for writing your applications and easily installing them into your projects including their dependencies. </li> </ul>  <p>I want to focus on Web Pages today which I’ve not written about since we released the first release but I’ve been involved in from the beginning. If you don’t have any background on Web Pages this is a very simple way to do web development drawling parallels to programming in classic ASP or PHP. It does not require development tools like Visual Studio, or a build system to build projects. You can just take an empty folder and and drop in a .cshtml (C#)or .vbhtml (Visual Basic) file into the folder that contains a combination of markup and razor syntax and point your browser and you are off and running.</p>  <p>For someone like myself Web Pages reminds me of when I first started web programming years ago with classic ASP. I could take my HTML files and add a little bit of inline code to get dynamic web pages. It was a great way to learn web programming and Web Pages brings this same simplicity to ASP.NET. All of the concepts you learn while programming in Web Pages you should be able to use if you decide to move up to our more complicated frameworks like MVC.</p>  <p>To learn more about Web Pages check out our online manual: <a title="https://www.asp.net/webmatrix/tutorials/1-getting-started-with-webmatrix-and-asp-net-web-pages" href="https://www.asp.net/webmatrix/tutorials/1-getting-started-with-webmatrix-and-asp-net-web-pages">https://www.asp.net/webmatrix/tutorials/1-getting-started-with-webmatrix-and-asp-net-web-pages</a>.</p>  <p>Today I’m going to talk about Request Validation which is a security feature that is built in ASP.NET. Request Validation is a security measure that is built into ASP.NET. The purpose of this feature is prevent script or HTML injection attack in websites. Such attacks happen when a webpage has some input fields on the page that accept input. If a person fills these input fields with script or html and the web page outputs the content back the user the web browser will run the script or html potentially causing the browser to do something bad.</p>  <p>To prevent this ASP.NET looks at any input that it sees and if it looks like unencoded html and error will happen and the request will not be processed. Lets take a simple application and see what this looks like:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;!</span><span style="color: #800000">DOCTYPE</span> <span style="color: #ff0000">html</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">html</span> <span style="color: #ff0000">lang</span><span style="color: #0000ff">=&quot;en&quot;</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">meta</span> <span style="color: #ff0000">charset</span><span style="color: #0000ff">=&quot;utf-8&quot;</span> <span style="color: #0000ff">/&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span><br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">form</span> <span style="color: #ff0000">method</span><span style="color: #0000ff">=&quot;post&quot;</span> <span style="color: #ff0000">action</span><span style="color: #0000ff">=&quot;&quot;</span><span style="color: #0000ff">&gt;</span><br />            <span style="color: #0000ff">&lt;</span><span style="color: #800000">label</span> <span style="color: #ff0000">for</span><span style="color: #0000ff">=&quot;description&quot;</span><span style="color: #0000ff">&gt;</span>Description:<span style="color: #0000ff">&lt;/</span><span style="color: #800000">label</span><span style="color: #0000ff">&gt;</span><br />            <span style="color: #0000ff">&lt;</span><span style="color: #800000">textarea</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;description&quot;</span><span style="color: #0000ff">&gt;</span><br />            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">textarea</span><span style="color: #0000ff">&gt;</span><br />            <span style="color: #0000ff">&lt;</span><span style="color: #800000">br</span> <span style="color: #0000ff">/&gt;</span><br />            <span style="color: #0000ff">&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;submit&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;Submit&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">input</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">form</span><span style="color: #0000ff">&gt;</span><br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">br</span> <span style="color: #0000ff">/&gt;</span><br />        @if (IsPost) {<br />            <span style="color: #0000ff">&lt;</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span><br />                Your description is: @Request[&quot;description&quot;]<br />            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span><br />        }<br />    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span></pre>

  <br /></div>

<div>&#160;</div>

<div>If I type something in the field on the page that looks like html:</div>

<div>&#160;</div>

<div><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/7357.image_4A5A5102.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/7357.image_5F00_4A5A5102.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/3323.image_thumb_6139227E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/3323.image_5F00_thumb_5F00_6139227E.png" width="527" height="202" /></a></div>

<p>And the press the submit button I will get an error instead of having my page run properly:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/5710.image_072ED2D5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/5710.image_5F00_072ED2D5.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/3731.image_thumb_34AFF298.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/3731.image_5F00_thumb_5F00_34AFF298.png" width="529" height="295" /></a></p>

<p>This shows an example of ASP.NET working to be secure by default and making the developer make the decision if they want allow such input. You might be asking yourself why would you want to allow someone to type html into a field. The best example is when you build a web page that contains a rich html editor, today you see these in all kinds of applications on the internet such as blogs. I’ve added the TinyMCE editor to my application because I want to have a rich editor. I downloaded the scripts from the TinyMCE site and added them to the scripts folder in my project. Next I added the following markup above my form:</p>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;script type=<span style="color: #006080">&quot;text/javascript&quot;</span> src=<span style="color: #006080">&quot;scripts/tiny_mce/tiny_mce.js&quot;</span>&gt;&lt;/script&gt;<br />&lt;script type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;<br />    tinyMCE.init({<br />        mode : <span style="color: #006080">&quot;textareas&quot;</span>,<br />        theme : <span style="color: #006080">&quot;simple&quot;</span><br />    });<br />&lt;/script&gt;        <br /></pre>
</div>

<div>&#160;</div>

<div>This enables the rich html editor on my page and running the page in the browser now looks like this: 
  <br /></div>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/3644.image_65CF2D38.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/3644.image_5F00_65CF2D38.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/4237.image_thumb_6C8236BB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/4237.image_5F00_thumb_5F00_6C8236BB.png" width="519" height="367" /></a></p>

<p>Now any in the description field will fail with the same server error we saw above when pressing the submit button. This is because the fancy effects of being able to bold, strike through and underline you see in the example above happen because the field contains html. I need someway of turning off the validation for just this one field. Older versions of ASP.NET have had ways of turning this off:</p>

<p><strong>ASP.NET 1.1 – ASP.NET 3.5 SP1:</strong></p>

<p>In Web Forms you can add the following page directive: &lt;%@ Page validateRequest=&quot;false&quot; %&gt;</p>

<p>In MVC you would place the following attribute on the action method for your controller: [ValidateInput(false)]</p>

<p>But these are not a good solution because they turn off Request Validation for the entire page! If I had other fields on the page for example a &lt;input type=”text” name=”name”/&gt; field in which I do not want to allow html or script input it is no longer protected because I’ve turned off request validation for the whole page. Now I need to manually validate the input for each field to make sure the input is safe.</p>

<p><strong>ASP.NET 4:</strong></p>

<p>We made Request Validation even stronger by making it happen earlier in the request pipeline. This meant that even low level ASP.NET components called Handlers and Modules could be protected. But because we are validating input so early you can no longer turn it on or off at the page level. If you had pages that needed to support html input you had to disable the .NET 4 mode and re-enable the .NET 1.1/2.0 mode using settings in the web.config file.</p>

<p><strong>The Future: Web Pages, MVC 3 and in the next framework Web Forms:</strong></p>

<p>Clearly we needed a much better solution. I should be able to turn off the request validation just for the fields that need to support html type input. While building Web Pages we were able to keep both the additional security we enabled in .NET 4 and support this using the new Validation.Exclude method. Here is how I add support for this by adding it to the top of my page:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">@{<br />    Validation.Exclude(<span style="color: #006080">&quot;description&quot;</span>);<br />}</pre>

  <br />You can pass multiple fields or if you want to disable Request Validation for the entire page you can call Validation.ExcludeAll. Now if I run the page in the browser you will see this:</div>

<div>&#160;</div>

<div><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/0511.image_212292F7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/0511.image_5F00_212292F7.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/8358.image_thumb_2BDFEA4C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/8358.image_5F00_thumb_5F00_2BDFEA4C.png" width="506" height="289" /></a></div>

<p>You might be asking yourself why does the text in the rich html editor look one way and when I display in the page does it look different? We have just run into another security feature that ASP.NET razor syntax has, whenever we output values we automatically encode them:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">Your description <span style="color: #0000ff">is</span>: @Request[<span style="color: #006080">&quot;description&quot;</span>]<br /></pre>
The value of @Request[“description”] is automatically html encoded. This again is an example of security being on by default so if values containing html or script are output the browser will not execute the html/script. If the developer knows that the data they are outputing is valid they can create a special type called an HtmlString and return the value of that which will not be automatically encoded. Here is&#160; the changed code in my sample:</div>

<div>&#160;</div>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #cc6633">@if</span> (IsPost) {<br />    <span style="color: #0000ff">var</span> desc = <span style="color: #0000ff">new</span> HtmlString(Request[<span style="color: #006080">&quot;description&quot;</span>]);<br />    &lt;div&gt;<br />        Your description <span style="color: #0000ff">is</span>: <span style="color: #cc6633">@desc</span><br />    &lt;/div&gt;<br />}<br /></pre>

  <br /></div>

<div id="codeSnippetWrapper">Now I’m grabbing the value of the Request and creating a new HtmlString with that value. HtmlString is a special type that ASP.NET does not encode when it is output. Now running my page I will get the output I expect:</div>

<div>&#160;</div>

<div><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/0842.image_24547ADF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/0842.image_5F00_24547ADF.png"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/6864.image_thumb_2B078462.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/6864.image_5F00_thumb_5F00_2B078462.png" width="326" height="355" /></a></div>

<p>In this blog post I’ve covered a lot of topics but to recap:</p>

<ul>
  <li>- Web Pages validates input by default for security </li>

  <li>- Web pages allows this validation to be disabled on a field by field basis </li>

  <li>- Web pages encodes output by default for security </li>

  <li>- Web pages allows output to be put into an HtmlString which allows it to be output with encoding </li>
</ul>

<p>I hope to post about more Web Pages features soon…</p>]]></content:encoded>
    </item>
    <item>
      <title>GridView with Sort Arrows and Showing Header When Empty</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/gridview-with-sort-arrows-and-showing-header-when-empty</link>
      <pubDate>Sat, 28 Aug 2010 19:02:04 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2010/08/28/gridview-with-sort-arrows-and-showing-header-when-empty/</guid>
      <description><![CDATA[One of the common things people want to do when displaying data with grid controls is to have the...]]></description>
      <content:encoded><![CDATA[<p>One of the common things people want to do when displaying data with grid controls is to have the little up and down arrows next to the header columns to indicated what direction the data is being sorted in. You see this in Windows Explorer and many other programs. This has been traditionally something that is difficult to do with the GridView control in ASP.NET. If you search the internet you will find a variety of hacks to do this:</p>  <p>Matt Berseth: <a href="https://mattberseth.com/blog/2008/04/building_a_vs2008_styled_grid_1.html" target="_blank">Building a VS2008 Styled Grid with the GridView Control</a></p>  <p>4 Guys From From Rolla.com: <a href="https://www.4guysfromrolla.com/articles/020608-1.aspx" target="_blank">Improving the Sort Arrows GridView Control</a></p>  <p>Some of these implementations have various limitations such as they don’t work if you use AutoGenerateColumns = true. In .NET 4 we addressed these problems by adding a couple of new properties to the GridView:</p>  <p><a href="https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortedascendingheaderstyle.aspx" target="_blank">&lt;SortedAscendingHeaderStyle /&gt;</a>    <br /><a href="https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorteddescendingheaderstyle.aspx" target="_blank">&lt;SortedDescendingHeaderStyle /&gt;</a>    <br /><a href="https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortedascendingcellstyle.aspx" target="_blank">&lt;SortedAscendingCellStyle /&gt;</a>    <br /><a href="https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorteddescendingcellstyle.aspx" target="_blank">&lt;SortedDescendingCellStyle /&gt;</a></p>  <p>These allow you to easily set specific styles on both the header cells and the item cells of the GridView. Here is an example of this put to use in a GridView:</p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> &lt;asp:GridView ID=<span style="color: #006080">&quot;GridView1&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span> AllowSorting=<span style="color: #006080">&quot;True&quot;</span> DataSourceID=<span style="color: #006080">&quot;EntityDataSource1&quot;</span> PageSize=<span style="color: #006080">&quot;5&quot;</span>&gt;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>     &lt;SortedAscendingHeaderStyle CssClass=<span style="color: #006080">&quot;sortasc&quot;</span> /&gt;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     &lt;SortedDescendingHeaderStyle CssClass=<span style="color: #006080">&quot;sortdesc&quot;</span> /&gt;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> &lt;/asp:GridView&gt;</pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>

<p>What this does in when the grid is being sorted the header of the grid the sortasc or sortdesc class will be applies to the header cell like this depending on the direction it is being sorted on:</p>

<p>&lt;th style=”sortasc”&gt;Column Header&lt;/th&gt;</p>

<p>&lt;th style=”sortdesc”&gt;Column Header&lt;/th&gt;</p>

<p>And I’ve got some simple CSS defined that will apply a sort arrow:</p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> th.sortasc a  </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     display:block; padding:0 4px 0 15px; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     background:url(img/asc.gif) no-repeat;  </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> }</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>&#160; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> th.sortdesc a </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span> {</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     display:block; padding:0 4px 0 15px; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>     background:url(img/desc.gif) no-repeat;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span> }</pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>

<p>The end result will look like this showing the grid sorting each direction on the LastName column with nice arrows showing the direction.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/1030.image_0FDBC559.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/1030.image_5F00_0FDBC559.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/8284.image_thumb_79397711.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/8284.image_5F00_thumb_5F00_79397711.png" width="192" height="244" /></a>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/3482.image_2DD9D34D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/3482.image_5F00_2DD9D34D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/4075.image_thumb_1F9B5A5D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/4075.image_5F00_thumb_5F00_1F9B5A5D.png" width="192" height="244" /></a></p>

<p>I’ve created a sample of this you can download and try out: <a href="https://www.cshonline.com/aspnet/gridsortarrows.zip" target="_blank">https://www.cshonline.com/aspnet/gridsortarrows.zip</a>.</p>

<p>Another common request for the GridView deals with how it displays when there is no data. It basically does not display at all. You will basically see a set of empty &lt;div&gt;&lt;/div&gt; tags in the page. There is a template inside the Grid that you can use to display some text:</p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">EmptyDataTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>     Empty GridView</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">EmptyDataTemplate</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>

<p>But a lot of the time what you really want is to display the header row of the Grid showing what <strong>COULD</strong> be displayed. Once again if you search around the Internet you might find hacks to show the header. Once again because this was a common ask we added support for this in .NET 4. You can now use the ShowHeaderWhenEmpty property to show the header. Here is what the markup would look like:</p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> &lt;asp:GridView ID=<span style="color: #006080">&quot;GridView1&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span> DataSourceID=<span style="color: #006080">&quot;EntityDataSource1&quot;</span> ShowHeaderWhenEmpty=<span style="color: #006080">&quot;true&quot;</span>&gt;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> &lt;/asp:GridView&gt;</pre>
<!--crlf--></!--crlf--></!--crlf--></div>
</div>

<p>And here is what a GridView would display with no data with this property enabled:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/4578.image_264E63E0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/4578.image_5F00_264E63E0.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/8875.image_thumb_2D016D63.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/8875.image_5F00_thumb_5F00_2D016D63.png" width="244" height="206" /></a></p>

<p>Hopefully all of these new options will make using the GridView easier. Enjoy!</p>]]></content:encoded>
    </item>
    <item>
      <title>PersistedSelection in Data Controls in .NET 4</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/persistedselection-in-data-controls-in-net-4</link>
      <pubDate>Thu, 26 Aug 2010 21:55:01 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2010/08/26/persistedselection-in-data-controls-in-net-4/</guid>
      <description><![CDATA[We did a variety of small feature items across the data controls when we were working on .NET 4 and...]]></description>
      <content:encoded><![CDATA[<p>We did a variety of small feature items across the data controls when we were working on .NET 4 and I’m going to do a couple of blog posts on some of this new functionality. When we were building Dynamic Data we made small enhancements to the data controls but they only worked when you were using Dynamic Data. In .NET 4 we took this functionality and made it work across all of our core data controls.</p>  <p><strong>Persisted Selection</strong></p>  <p>When using our data controls that support paging like GridView and ListView there is some funky behavior today. If the user selects the first row of data and then moves to the next page the first row of the data is selected. This behavior seems weird, especially when you are in a master detail scenario where you show the details of the selected row on the same page. As you page through your data the detail view would keep changing as you move from page to page. Here is what the old behavior looks like:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/1856.image_402BADE3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/1856.image_5F00_402BADE3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/0702.image_thumb_2BC5E858.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/0702.image_5F00_thumb_5F00_2BC5E858.png" width="284" height="225" /></a>&#160;&#160;&#160;&#160;&#160;&#160; </p>  <p>You can see in the first image that the second row is selected.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/2043.image_048B9F23.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/2043.image_5F00_048B9F23.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/8132.image_thumb_0B3EA8A6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/8132.image_5F00_thumb_5F00_0B3EA8A6.png" width="286" height="227" /></a></p>    <p>As I move to the second page the second row which is a different user is selected. This is probably not what a user would expect when using the controls. Now I’m going to enable a new property on the control called EnablePersistedSelelection and set it to true.</p>    <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> EnablePersistedSelection=<span style="color: #006080">&quot;true&quot;</span></pre>
<!--crlf--></!--crlf--></div>
</div>

<p>And now we can look and see what the behavior looks like:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/2330.image_11F1B229.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/2330.image_5F00_11F1B229.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/0218.image_thumb_18A4BBAC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/0218.image_5F00_thumb_5F00_18A4BBAC.png" width="230" height="244" /></a>&#160;&#160;&#160;&#160;&#160; </p>

<p>You can now see that I select Scott Hunter in the first page. </p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/2450.image_716A7276.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/2450.image_5F00_716A7276.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/2043.image_thumb_632BF986.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/2043.image_5F00_thumb_5F00_632BF986.png" width="230" height="244" /></a></p>

<p>And move to the second page and no row is selected.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/8132.image_50E332C4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/8132.image_5F00_50E332C4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/95/25/metablogapi/8625.image_thumb_57963C47.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-95-25-metablogapi/8625.image_5F00_thumb_5F00_57963C47.png" width="230" height="244" /></a></p>

<p>but moving back to the first page Scott Hunter is still selected. This should make master / detail view work better we think this is the behavior that someone would expect when using the control anyways.</p>]]></content:encoded>
    </item>
    <item>
      <title>Automatically prepopulate fields for Insert in .NET 4</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/automatically-prepopulate-fields-for-insert-in-net-4</link>
      <pubDate>Thu, 26 Aug 2010 00:35:00 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2010/08/26/automatically-prepopulate-fields-for-insert-in-net-4/</guid>
      <description><![CDATA[We introduced a lot of little data enhancements in .NET 4 that you may not have heard about. One of...]]></description>
      <content:encoded><![CDATA[<p>We introduced a lot of little data enhancements in .NET 4 that you may not have heard about. One of these is a mechanism for setting the default value of fields in a data control when you want to do an Insert. In our controls today you would probably do something painful:</p>
<p>- Handle the ItemCreated event and inside the event you can call FindControl and find the control for each column manually and set the value on the control using whatever property it supports to set its control.</p>
<p>- Handle the Inserting event on the data source control (if you are using one) and check to see if fields have values and if not set the default. This is problematic because this happens after the user has pressed Insert so they do not see the default value until AFTER the insert operation.</p>
<p>One of the features we enabled in .NET 4 was the ability to enable Dynamic Data functionality with a single line of code in an existing web page. By enabling Dynamic Data you can easily use some of its features to make this super simple.</p>
<p>In my example I&rsquo;ve got a table called Contact which has an Id, FirstName, LastName and Age fields. I&rsquo;ve created an Entity Framework model around my database giving me rich classes for the tables in my database. Here is what my page markup looks like:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:DetailsView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="DetailsView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Height</span><span style="color: #0000ff">="50px"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="125px"</span> </pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #ff0000">AutoGenerateRows</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">DataKeyNames</span><span style="color: #0000ff">="Id"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="EntityDataSource1"</span> </pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #ff0000">DefaultMode</span><span style="color: #0000ff">="Insert"</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">Fields</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:CommandField</span> <span style="color: #ff0000">ShowInsertButton</span><span style="color: #0000ff">="True"</span> <span style="color: #0000ff">/&gt;</span></pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Fields</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060">   7:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:DetailsView</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060">   8:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:EntityDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="EntityDataSource1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="name=DatabaseEntities"</span> <span style="color: #ff0000">DefaultContainerName</span><span style="color: #0000ff">="DatabaseEntities"</span> <span style="color: #ff0000">EnableFlattening</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">EnableInsert</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">EntitySetName</span><span style="color: #0000ff">="Contacts"</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060">   9:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:EntityDataSource</span><span style="color: #0000ff">&gt;</span></pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>
<p>And here is what my code behind markup looks like:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> DetailsView1.EnableDynamicData(<span style="color: #0000ff">typeof</span>(DatabaseModel.Contact));</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> var contact = <span style="color: #0000ff">new</span> DatabaseModel.Contact();</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span> contact.FirstName = <span style="color: #006080">"Scott"</span>;</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span> contact.LastName = <span style="color: #006080">"Guthrie"</span>;</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span> DetailsView1.SetMetaTable(DetailsView1.GetMetaTable(), contact);</pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>
<p>My code is doing a couple of items here:</p>
<p>1: Enabling Dynamic Data functionality for the data control passing it the type of data the control is hosting. This is the object from my Entity Framework model.</p>
<p>2 &ndash; 4: Creating a dummy record of Contact and filling in the fields with whatever data I want to use for my defaults.</p>
<p>5: Calling the SetMetaTable method on the data control passing the MetaTable which I get from the GetMetaTable method on the control and then passing my object that contains the default values.</p>
<p>Now if I run my page I will get the DetailsView to show up with my defaults automatically set. Note in my example I&rsquo;m using auto generated columns. If you choose to manually specify your columns you will need to specify them using either DynamicField (DetailsView/GridView) or DynamicControl (FormView/ListView) for this functionality to work because these types inject Dynamic Data fields templates which allow this insert functionality to work.</p>
<p>Also you can also specify the defaults using a dictionary if you don&rsquo;t want to create a full object. Here is an example of what that would look like:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060">   1:</span> DetailsView1.EnableDynamicData(<span style="color: #0000ff">typeof</span>(DatabaseModel.Contact));</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060">   2:</span> var contact = <span style="color: #0000ff">new</span> Dictionary&lt;<span style="color: #0000ff">string</span>, <span style="color: #0000ff">object</span>&gt;() {</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060">   3:</span>     {<span style="color: #006080">"FirstName"</span>, <span style="color: #006080">"Scott"</span>},</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060">   4:</span>     {<span style="color: #006080">"LastName"</span>, <span style="color: #006080">"Guthrie"</span>}</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060">   5:</span> };</pre>
<!--crlf-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060">   6:</span> DetailsView1.SetMetaTable(DetailsView1.GetMetaTable(), contact);</pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>
<p>I&rsquo;ve created a fully running sample of this you can download as well. The sample requires .NET 4, VS 2010 and SQL Express 2008 to be installed to run. Here is the link the sample: <a href="https://www.cshonline.com/aspnet/insertdefaults.zip">https://www.cshonline.com/aspnet/insertdefaults.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Program Manager Position on the ASP.NET PM team</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/program-manager-position-on-the-asp-net-pm-team</link>
      <pubDate>Mon, 23 Nov 2009 14:14:00 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2009/11/23/program-manager-position-on-the-asp-net-pm-team/</guid>
      <description><![CDATA[Are you interested in making a change? Do you want to join a fast moving team inside of Microsoft...]]></description>
      <content:encoded><![CDATA[<P>Are you interested in making a change? Do you want to join a fast moving team inside of Microsoft and help drive the future features in ASP.NET?We have a program manager position on the ASP.NET team which is currently available. You can access the listing here: <A href="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=0&amp;so=&amp;rw=1&amp;jid=9482&amp;jlang=EN" mce_href="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=0&amp;so=&amp;rw=1&amp;jid=9482&amp;jlang=EN">ASP.NET PM Position</A>. We are looking for someone that is interested in driving the data strategy on our team which includes partnering with LINQ and SQL teams, is into web standards around HTML, CSS and JavaScript and making ASP.NET work better with these standards and much much more. Please check out the listing if you are interested.</P>]]></content:encoded>
    </item>
    <item>
      <title>Data Enhancements in .NET 4 / Visual Studio 2010 Beta 2</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/data-enhancements-in-net-4-visual-studio-2010-beta-2</link>
      <pubDate>Tue, 20 Oct 2009 23:40:14 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2009/10/20/data-enhancements-in-net-4-visual-studio-2010-beta-2/</guid>
      <description><![CDATA[On Wednesday we are releasing .NET 4 / Visual Studio 2010 Beta 2 to the public and&#160; it brings...]]></description>
      <content:encoded><![CDATA[<p>On Wednesday we are releasing .NET 4 / Visual Studio 2010 Beta 2 to the public and&#160; it brings many cool enhancements to the ASP.NET data controls and Entity Framework. I’m going to drill into a few features of these data related features and you can read more about all the changes to ASP.NET 4 at: <a title="https://www.asp.net/learn/whitepapers/aspnet40/" href="https://www.asp.net/learn/whitepapers/aspnet40/">https://www.asp.net/learn/whitepapers/aspnet40/</a>. This contains a very detailed list of all the changes we have made in ASP.NET.</p>  <p>Here are a couple of my favorite “data” related features:</p>  <p>1) The Entity Framework now supports the ability to the ability to pluralize entity sets and singularize entities. This means when I refer the table the table will be called “Products” but the actual class that I work on in my application is a “Product”. This feels much more natural then Entity Framework 1 where I would write:</p>  <p>Products product = new Products();</p>  <p>while in 4.0 this becomes:</p>  <p>Product product = new Product();</p>  <p>which feels more natural and looks better in my code.</p>  <p>Here is the UI in the Entity Model Wizard for enabling this (note it turned on by default)</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_2.png" original-url="https://blogs.msdn.com/blogfiles/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_thumb.png" width="244" height="66" /></a> </p>  <p>2) The Entity Framework now supports the ability to include “foreign keys” in the data model. In version 1 of the Entity Framework if I had a Product table that contained a CategoryID which referenced a record in the Category table the generated Entity Framework model would convert the CategoryID into a navigation property which would drill directly in the category table. While this simplified some scenario’s it made web scenarios more difficult. Normally I would represent the this in using a DropDownList control which would contain the primary key and the name of the records from the category table. When saving saving the record I would just want to assign the selected CategoryID from the DropDownList to the Product class. But with navigation properties I would have to revert to some very ugly and non-discoverable code for setting the CategoryID since it not exist. Entity Framework 4 now includes the ability to have foreign key columns added directly to the entity allowing me to either set the foreign key or the navigation property making web scenarios easier to program:</p>  <p>&#160;</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_4.png" original-url="https://blogs.msdn.com/blogfiles/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_thumb_1.png" width="124" height="244" /></a><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_6.png" original-url="https://blogs.msdn.com/blogfiles/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/scothu/WindowsLiveWriter/DataEnhancemen.NET4VisualStudio2010Beta2_14CDC/image_thumb_2.png" width="110" height="244" /></a></p>  <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EF 1.0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EF 4.0&#160; </p>  <p>3) QueryExtender support is now available for EntityDataSource. In .NET 4 Beta 1 and in the Dynamic Data Preview releases on CodePlex we introduced a very exciting extender control for the LinqDataSource called the QueryExtender. We created this control in response to feedback we received after releasing Dynamic Data 1.0 that our customers wanted an easy way of filtering or searching the data that their data source controls returned aka “How do I implement a search”. This pattern with data source controls can get fairly complicated and we wanted to provide something simple. The QueryExtender allows the following types of searches:</p>  <p>Search: Searched for a string across any number of columns</p>  <p>Range: Filters data based on if the value of a column is between a given range</p>  <p>Property: Filters based on a column matching a value </p>  <p>Custom: Event is fired in which the developer can customize the LINQ expression.</p>  <p>Here is an example of using the QueryExtender with the EntityDataSource. It takes the value from TextBox1 and uses compares it to the ProductName field and only returns rows which have the text from TextBox1 in the ProductName field:</p>  <p>&lt;asp:EntityDataSource ID=&quot;EntityDataSource1&quot; runat=&quot;server&quot;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConnectionString=&quot;name=NORTHWNDEntities&quot;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; DefaultContainerName=&quot;NORTHWNDEntities&quot; EnableDelete=&quot;True&quot;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnableFlattening=&quot;False&quot; EnableInsert=&quot;True&quot; EnableUpdate=&quot;True&quot;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; EntitySetName=&quot;Products&quot;&gt;    <br />&lt;/asp:EntityDataSource&gt;    <br /><strong>&lt;asp:QueryExtender ID=&quot;QueryExtender1&quot; runat=&quot;server&quot; TargetControlID=&quot;EntityDataSource1&quot;&gt;     <br />&#160;&#160;&#160; &lt;asp:SearchExpression SearchType=&quot;Contains&quot; DataFields=&quot;ProductName&quot;&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;asp:ControlParameter ControlID=&quot;TextBox1&quot; /&gt;      <br />&#160;&#160;&#160; &lt;/asp:SearchExpression&gt;      <br />&lt;/asp:QueryExtender&gt; </strong></p>  <p>4) EnableDynamicData extension method. We introduced Dynamic Data in .NET 3.5 SP1 but it put some serious demands on the developer: Required the developer to be using Linq to SQL or Entity Framework, Required the developer to start a new project to get the Dynamic Data support files, Provided a different programming model. With Beta 2 we have added this new feature which can be enabled on our data controls like this:</p>  <p>ListView1.EnableDynamicData(typeofProduct))</p>  <p>This one line of code will automatically bring many of the features that Dynamic Data provides:</p>  <p>- Automatic validation</p>  <p>- Support for Data Annotations on objects to control validation and display properties</p>  <p>- Support for field templates for customizing UI behavior based on data type</p>  <p>This should allow any developer to utilize the power of Dynamic Data without radically changing their application or requiring Linq to SQL or Entity Framework.</p>  <p>There are many other changes and updates to our data support and I will try and blog about it over the next few weeks.</p>]]></content:encoded>
    </item>
    <item>
      <title>Dynamic Data Preview 4 Released</title>
      <link>https://docs.microsoft.com/archive/blogs/scothu/dynamic-data-preview-4-released</link>
      <pubDate>Thu, 07 May 2009 04:29:39 GMT</pubDate>
      <dc:creator><![CDATA[Scott H]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/scothu/2009/05/07/dynamic-data-preview-4-released/</guid>
      <description><![CDATA[Today we released the newest preview release of Dynamic Data. You can view the details and download...]]></description>
      <content:encoded><![CDATA[<p>Today we released the newest preview release of Dynamic Data. You can view the details and download this release from here: <a title="https://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27026" href="https://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27026">https://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27026</a>.</p>  <p>&#160;</p>  <p>The preview releases of Dynamic Data contain much of the new feature sets that will be available when we release .NET 4. The cool thing is you can start using a lot of the new features against .NET 3.5 SP1 now using these releases.</p>  <p>&#160;</p>  <p>When we look back and see how people view Dynamic Data we regret that people immediately think of it as scaffolding of data. This is something that it does do, and I think it does a pretty good job at it. But Dynamic Data is a lot more then that, providing a new templating mechanism called Field Templates which allow the default markup for many of our built in data controls to be more easily customized. These field templates also support validation by default (something our rich data controls did not) which can be customized by adding metadata to data objects.</p>  <p>&#160;</p>  <p>In the past to enable Dynamic Data functionality in a web application the application needed to follow a couple of rules:</p>  <p>- It had to have a data model such as Entity Framework or Linq to SQL</p>  <p>- The data model had to be registered at startup in Global.asax</p>  <p>- The DynamicData directory had to exist in the web application</p>  <p>&#160;</p>  <p>One of the new features this new preview release supports is adding field templates and validation to any ASP.NET web page without having to meet these requirements. It is as simple as:</p>  <p>&#160;</p>  <p>GridView1.EnableDynamicData(typeof(Product));</p>  <p>&#160;</p>  <p>What does this do for you? Today a control like GridView supports all kinds of high level features such as paging, sorting, viewing, editing but it provides no validation of data at all. So if your database has an integer field the end user would be able to type any data they wanted and when saving the record an ASP.NET yellow screen of death screen would appear (on the development box) saying that the data could not be converted to an integer. By enabling Dynamic Data automatic validation will occur because validation is built into the field templates that would render the column and a nice error message will appear in the page saying “Field XYZ must be an integer”.</p>  <p>&#160;</p>  <p>To see this in action download the preview release and try out the SimpleDynamicDataSample.</p>]]></content:encoded>
    </item>
  </channel>
</rss>