<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://strangenut.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">.NET Programming Blog</title><subtitle type="html" /><id>http://strangenut.com/blogs/clr-programming-blog/atom.aspx</id><link rel="alternate" type="text/html" href="http://strangenut.com/blogs/clr-programming-blog/default.aspx" /><link rel="self" type="application/atom+xml" href="http://strangenut.com/blogs/clr-programming-blog/atom.aspx" /><generator uri="http://communityserver.org" version="4.0.30619.63">Community Server</generator><updated>2008-11-13T17:47:00Z</updated><entry><title>How to enable Network Level Authentication for Remote Desktop on Windows XP</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2010/07/03/how-to-enable-network-level-authentication-for-remote-desktop-on-windows-xp.aspx" /><id>/blogs/clr-programming-blog/archive/2010/07/03/how-to-enable-network-level-authentication-for-remote-desktop-on-windows-xp.aspx</id><published>2010-07-03T20:22:00Z</published><updated>2010-07-03T20:22:00Z</updated><content type="html">&lt;p&gt;When connecting to a Windows Server 2008 or newer remote host using remote desktop, you get an error saying that &amp;quot;The remote computer requires Network Level Authentication, which your computer does not support.&amp;quot;&lt;/p&gt;
&lt;p&gt;To enable Network Level Authentication (NLA) on Windows XP you need to do the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install Service Pack 3&lt;/li&gt;
&lt;li&gt;Click Start-&amp;gt;Run, type regedit and then press enter&lt;/li&gt;
&lt;li&gt;In the left pane, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa&lt;/li&gt;
&lt;li&gt;In the right pane, double click &amp;quot;Security Packages&amp;quot;, this brings up a dialog box to modify the values, leave all existing values as they are, and at the end of the list add &amp;quot;tspkg&amp;quot;, and click OK.&lt;/li&gt;
&lt;li&gt;In the left pane, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders, and in the right pane double click SecurityProviders, and in the dialog box, add &amp;quot;credssp.dll&amp;quot; to the end, be sure that if the list that is present currently is separated by commas, that you add a comma to the value immediately before the &amp;quot;credssp.dll&amp;quot; that you just added. Click OK to save your changes.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Exit the registry editor and restart your computer.&lt;/li&gt;
&lt;li&gt;Reattempt your remote desktop connection.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=61" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="server 2008 r2" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/server+2008+r2/default.aspx" /><category term="Network Level Authentication" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Network+Level+Authentication/default.aspx" /></entry><entry><title>How to edit the password policy on Windows Server 2008 R2 with Active Directory</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2010/07/03/how-to-edit-the-password-policy-on-windows-server-2008-r2-with-active-directory.aspx" /><id>/blogs/clr-programming-blog/archive/2010/07/03/how-to-edit-the-password-policy-on-windows-server-2008-r2-with-active-directory.aspx</id><published>2010-07-03T19:14:00Z</published><updated>2010-07-03T19:14:00Z</updated><content type="html">&lt;p&gt;When setting up a new Windows Server 2008 server either with or without Active Directory you will discover that it has a rather strong policy for passwords.&amp;nbsp; If you are setting this up at home or in a small business environment and don&amp;#39;t want to deal with the complex passwords that are required to meet the policy guidelines, you can edit the policy to disable the complexity requirements.&amp;nbsp; You can try going to a command prompt and typing &amp;#39;gpedit.msc&amp;#39; then navigating to Computer Settings\Windows Settings\Security Settings\Account Policies\Password Policy\ section.&lt;/p&gt;
&lt;p&gt;Here you will see the &amp;#39;Password must meet complexity requirements&amp;#39; item.&amp;nbsp; When viewing the properties of it, usually the Enabled/Disabled radio buttons will be grayed out and you cannot change the values.&amp;nbsp; If they are able to be changed, go ahead and do it, and save out of the dialog boxes.&amp;nbsp; If it is grayed out and you cannot change it here, this is how you do it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to a command prompt&lt;/li&gt;
&lt;li&gt;Type &amp;#39;secedit /export /cfg c:\local.cfg&amp;#39; and hit enter&lt;/li&gt;
&lt;li&gt;Using notepad, edit c:\local.cfg&lt;/li&gt;
&lt;li&gt;Look for the line &amp;quot;PasswordComplexity = 1&amp;quot; and change it to &amp;quot;PasswordComplexity = 0&amp;quot;&lt;/li&gt;
&lt;li&gt;You can also edit &amp;quot;MinimumPasswordLength = 7&amp;quot; to a lesser value if you like.&lt;/li&gt;
&lt;li&gt;Save the file&lt;/li&gt;
&lt;li&gt;At a command prompt type &amp;#39;secedit /configure /db %windir%\security\local.sdb /cfg c:\local.cfg /areas SECURITYPOLICY&lt;/li&gt;
&lt;li&gt;This will apply the new settings and refreshing the gpedit.msc should reflect the new settings&lt;/li&gt;
&lt;li&gt;Set your new less complex password!&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=59" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="group policy editor" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/group+policy+editor/default.aspx" /><category term="server 2008 r2" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/server+2008+r2/default.aspx" /><category term="password policy" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/password+policy/default.aspx" /></entry><entry><title>How to Get Started With ADO.NET Entity Framework 4 and Visual Studio 2010 (Beta 2)</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2010/01/31/how-to-get-started-with-ado-net-entity-framework-4-and-visual-studio-2010-beta-2.aspx" /><link rel="enclosure" type="application/zip" length="195574" href="http://strangenut.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.00.54/EntityFrame4Test.zip.zip" /><id>/blogs/clr-programming-blog/archive/2010/01/31/how-to-get-started-with-ado-net-entity-framework-4-and-visual-studio-2010-beta-2.aspx</id><published>2010-01-31T23:03:00Z</published><updated>2010-01-31T23:03:00Z</updated><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;The upcoming release of the .NET Framework version 4.0 and the simultaneous release of Visual Studio 2010 comes with a host of upgrades to the Entity Framework.&amp;nbsp; The Entity Framework is Microsofts officially supported Object Relational Mapping (ORM) tool used to connect .NET based applications and websites to the databases that run them.&amp;nbsp; It provides strongly typed access to the underlying tables and comes with full integration with LINQ.&amp;nbsp; The goal of this post is to help you get your feet wet with a step by step tutorial on the Entity Framework 4 and integrating it with a simple ASP.NET based web application.&lt;/p&gt;
&lt;p&gt;What you will need to get started to follow along with this tutorial on your own and to use the associated code download:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Download and install the &lt;a target="_blank" title="Download Visual Studio 2010 Ultimate Beta 2" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=92c65d2d-0a6b-4507-a4dc-767f4cc6e823&amp;amp;displaylang=en"&gt;Visual Studio 2010 Ultimate Beta 2&lt;/a&gt; release, and do a full install.&lt;/li&gt;
&lt;li&gt;&lt;a target="_blank" title="Download SQL Server 2008 Express" href="http://www.microsoft.com/express/Database/"&gt;SQL 2008 Express&lt;/a&gt; installed locally on your development workstation&lt;/li&gt;
&lt;li&gt;&lt;a title="The optional code download for this project" href="http://strangenut.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.00.54/EntityFrame4Test.zip.zip"&gt;The optional code download of this project&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Getting Started&lt;/h2&gt;
&lt;p&gt;First, open up Visual Studio and click on File -&amp;gt; New -&amp;gt; Project, select &amp;quot;ASP.NET Web Application&amp;quot; and name it EntityFramework4Test, and click OK.&amp;nbsp; This will create a very basic web application with all of the references that we need already set.&amp;nbsp; The project will open to the source view of the Default.aspx page, with some stub code that Microsoft puts there by default.&amp;nbsp; Go ahead and clear out everything inside of the &amp;lt;asp:Content ID=&amp;quot;&lt;b&gt;BodyContent&lt;/b&gt;&amp;quot;....&amp;gt; tag.&amp;nbsp; We will be back here in a moment.&lt;/p&gt;
&lt;p&gt;Next, right click on the &lt;b&gt;EntityFramework4Test&lt;/b&gt; project in the solution explorer (the line directly below &amp;quot;Solution &amp;#39;EntityFramework4Test&amp;#39; (1 Project) at the top), and click Add -&amp;gt; New Item.&amp;nbsp; From this dialog window click on &lt;b&gt;Data&lt;/b&gt; in the left pane; this will filter down to a shorter list of items, from this list select &lt;b&gt;ADO.NET Entity Data Model&lt;/b&gt;, name it &lt;b&gt;Demo.edmx&lt;/b&gt; and click Add.&amp;nbsp; The next window will ask &amp;quot;What should the model contain?&amp;quot; and give you the choice between &amp;quot;Generate from database&amp;quot; and &amp;quot;Empty Model&amp;quot;.&amp;nbsp; Select &lt;b&gt;Empty Model&lt;/b&gt; and click Next.&amp;nbsp; The next screen will ask which data connection to use.&amp;nbsp; We&amp;#39;ll name our database here Demo, so if you have a Demo database that you are already using, just substitute what ever name you like for Demo.&amp;nbsp; Set up a new connection to this database and if it needs created, let the process create it.&amp;nbsp; When it is done, it will bring up the Demo.edmx designer window with a blank slate.&lt;/p&gt;
&lt;h2&gt;Creating the Entities&lt;/h2&gt;
&lt;p&gt;Right click on the blank designer and click &lt;b&gt;Add&lt;/b&gt; -&amp;gt; &lt;b&gt;Entity...&lt;/b&gt; leave all of the fields in their default state, except for the Entity Name field, let&amp;#39;s fill that out with &amp;quot;Person&amp;quot;.&amp;nbsp; When we do this, notice lower down on the dialog window, the &amp;quot;Entity Set&amp;quot; field.. it automatically types with you and pluralizes the word for you.&amp;nbsp; In this case, its &amp;quot;People&amp;quot; - this is the property by which we will later refer to a Collection of Person objects.&amp;nbsp; Click OK, and the entity will be added to the designer.&amp;nbsp; Repeat this process and add an entity named Group.&lt;/p&gt;
&lt;p&gt;Since these entities will refer directly to database tables, we need to construct them in a manner consistent with how we design tables.&amp;nbsp; The entities by default have a primary key defined on them called &amp;quot;Id&amp;quot;; however these fields are not automatically marked as identity.&amp;nbsp; Right click on each of the Id fields, select &lt;b&gt;Properties&lt;/b&gt; and in the Properties window, look for the field labeled &amp;quot;&lt;b&gt;StoreGeneratedPattern&lt;/b&gt;&amp;quot;&amp;nbsp; - this will indicate that the Store (data repository, i.e. database) will generate this value and that we do not need to be concerned with setting this value.&lt;/p&gt;
&lt;p&gt;To add columns to the data entities, right click on them (note: right clicking on different areas of the Entity will give you different context menus, for this part, right click on the top of the Entity and Add should be the first context menu item.&amp;nbsp; When you find the Add menu item, select Add -&amp;gt; Scalar Property. It will add the field to the entity and allow you to change the name; after you name it, you can right click on the property field and select &amp;quot;Properties&amp;quot; and change the &lt;b&gt;Type&lt;/b&gt; to what ever is appropriate for the field we&amp;#39;re adding.&lt;/p&gt;
&lt;p&gt;Add the following fields to Person:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;FirstName - give it a type of String&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;LastName - give it a type of String&lt;/li&gt;
&lt;li&gt;EmailAddress - give it a type of String&lt;/li&gt;
&lt;li&gt;DateCreated - give it a type of DateTime&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Add the following fields to Group:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Name - give it a type of String&lt;/li&gt;
&lt;li&gt;DateCreated - give it a type of DateTime&lt;/li&gt;
&lt;li&gt;Description - give it a type of String&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Next, right click on the canvas again, and select Add -&amp;gt; Association; since we only have two entities right now, the the &lt;b&gt;Entity:&lt;/b&gt; drop down will already be populated with each of the entities.&amp;nbsp; Make sure that the &lt;b&gt;Multiplicity:&lt;/b&gt; drop downs both have &lt;b&gt;* (Many)&lt;/b&gt; selected.&amp;nbsp; This will allow this to be a Many to Many association.&amp;nbsp; We now have the basic data model setup for us to use, and we just need a database to back it all up.&lt;/p&gt;
&lt;p&gt;Right click on the canvas again, and select &lt;b&gt;Generate Database from Model&lt;/b&gt; and click Finish; this will bring up a T-SQL Editor window with the code necessary to create the schema.&amp;nbsp; The only change we should make alter the behavior of the foreign keys on the PersonGroup table.&amp;nbsp; The last line of the last ALTER TABLE statement is the one we want.&amp;nbsp; Change the ON DELETE NO ACTION ON UPDATE NO ACTION to ON DELETE CASCADE ON UPDATE CASCADE.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;This will automatically clear the records from the PersonGroup table when we delete rows from either Person or Group and prevent errors from being thrown or records being orphaned.&amp;nbsp; Hit CTRL+SHIFT+E to execute the SQL, it may prompt you to connect to the database server, if so go ahead and do so.&amp;nbsp; Provided it returns a message that the Command(s) completed successfully, we are now ready to use our Demo database.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;Note: If you are running the downloaded project, you will need complete this step yourself - my project assumes that you are using SQL Server Express 2008, and not a file based SQL Server Database.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;
&lt;h2&gt;Accessing the Data from ASP.NET&lt;/h2&gt;
&lt;p&gt;Now that our entities are set up and the database and tables are created, let&amp;#39;s open add a new Web Content Form to our web project.&amp;nbsp; Call it &lt;b&gt;AddPeopleAndGroup.aspx&lt;/b&gt; and click OK.&amp;nbsp; Inside the Page_Load method, past the following code (or reference the download project):&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&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; &lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&lt;span style="color:green;"&gt;//DemoEntities is the Type created that &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&lt;span style="color:green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //is the
context to the database.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using&lt;/span&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt;
context = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DemoEntities&lt;/span&gt;()) &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:green;"&gt;//let&amp;#39;s
create two people that we can add to a group&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Person&lt;/span&gt;
me = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Person&lt;/span&gt;()
&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;FirstName = &lt;span style="color:#a31515;"&gt;&amp;quot;Ryan&amp;quot;&lt;/span&gt;, &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;LastName = &lt;span style="color:#a31515;"&gt;&amp;quot;Crowley&amp;quot;&lt;/span&gt;, &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;EmailAddress = &lt;span style="color:#a31515;"&gt;&amp;quot;dontspamme@gmail.com&amp;quot;&lt;/span&gt;, &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;DateCreated = &lt;span style="color:#2b91af;"&gt;DateTime&lt;/span&gt;.Now &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;};&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Person&lt;/span&gt;
you = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Person&lt;/span&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;FirstName = &lt;span style="color:#a31515;"&gt;&amp;quot;Your&amp;quot;&lt;/span&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;LastName = &lt;span style="color:#a31515;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;EmailAddress = &lt;span style="color:#a31515;"&gt;&amp;quot;dontspamyou@gmail.com&amp;quot;&lt;/span&gt;,&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;DateCreated = &lt;span style="color:#2b91af;"&gt;DateTime&lt;/span&gt;.Now&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;};&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Group&lt;/span&gt;
ourGroup = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Group&lt;/span&gt;()&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Name = &lt;span style="color:#a31515;"&gt;&amp;quot;Our Group!&amp;quot;&lt;/span&gt;, &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&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;&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="font-size:9.5pt;font-family:Consolas;"&gt;Description = &lt;span style="color:#a31515;"&gt;&amp;quot;Our Group Description!&amp;quot;&lt;/span&gt;, &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;DateCreated= &lt;span style="color:#2b91af;"&gt;DateTime&lt;/span&gt;.Now&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;};&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:green;"&gt;//Add
the people to the group&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;ourGroup.People.Add(me);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;ourGroup.People.Add(you);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:green;"&gt;//Now
add the newly created Group to our table of Groups&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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;
&lt;/span&gt;context.Groups.AddObject(ourGroup);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:green;"&gt;//
this is the method call that will &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&lt;span style="color:green;"&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; // persist the entire set of objects to the
database&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;context.SaveChanges();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Running this code won&amp;#39;t output anything to the screen of course, but it will illustrate the simplicity of adding records to the database.&amp;nbsp; If we now go and select from all of our tables, we can see the data that we just saved.&amp;nbsp; Now, on to reading that data back out and displaying it!&lt;/p&gt;
&lt;h2&gt;Reading The Data&lt;/h2&gt;
&lt;p&gt;Let&amp;#39;s go into the Default.aspx file and add a GridView with the ID of &amp;quot;gvGroups&amp;quot; and one with the ID of &amp;quot;gvPeople&amp;quot;, and leave everything else default - this will let the GridViews auto generate the column names.&lt;/p&gt;
&lt;p&gt;Now let&amp;#39;s open up the Default.aspx.cs and paste the following code into it (again, or reference the download):&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt;
(&lt;span style="color:blue;"&gt;var&lt;/span&gt; context = &lt;span style="color:blue;"&gt;new&lt;/span&gt;
&lt;span style="color:#2b91af;"&gt;DemoEntities&lt;/span&gt;())&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;gvGroups.DataSource =
context.Groups;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;gvGroups.DataBind();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;gvPeople.DataSource =
context.People;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;gvPeople.DataBind();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:9.5pt;font-family:Consolas;"&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; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Voila! Running this will display two grids: one with the group that we just created and one with the people we just created.&lt;/p&gt;
&lt;p&gt;That&amp;#39;s all for this tutorial.&amp;nbsp; Soon there will be more examples posted as well as a series involving the construction of a more complex, fully functional application.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=54" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="C# 2008" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/C_2300_+2008/default.aspx" /><category term="ASP.NET" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/ASP.NET/default.aspx" /><category term="Visual Studio" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Visual+Studio/default.aspx" /><category term="Visual Studio 2010" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Visual+Studio+2010/default.aspx" /><category term="Entity Framework" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Entity+Framework/default.aspx" /><category term=".Net 4.0" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/.Net+4.0/default.aspx" /></entry><entry><title>ASP.NET MVC 2 and Html.RenderAction not working in Visual Studio 2010 Beta</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2010/01/21/asp-net-mvc-2-and-html-renderaction-not-working-in-visual-studio-2010-beta.aspx" /><id>/blogs/clr-programming-blog/archive/2010/01/21/asp-net-mvc-2-and-html-renderaction-not-working-in-visual-studio-2010-beta.aspx</id><published>2010-01-22T05:29:00Z</published><updated>2010-01-22T05:29:00Z</updated><content type="html">&lt;p&gt;So this week I&amp;#39;ve been working on an ASP.NET MVC 2 application and am using VS2010 Beta, and was stumped when Html.RenderAction() didn&amp;#39;t exist!&amp;nbsp; Documentation everywhere indicates that it did in fact become part of the main MVC product, but why does it not exist?&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Well, it does, but it appears to have been moved... though I am not quite sure why this hasn&amp;#39;t been documented or even yet referenced anywhere online. &lt;/p&gt;
&lt;p&gt;At first I had registered the Microsoft.Web.Mvc namespace in my web.config.. nothing.. &lt;/p&gt;
&lt;p&gt;Registered, imported and otherwise used fully qualified paths to Microsoft.Web.Mvc directly in my Master page.&amp;nbsp; Still nothing.&lt;/p&gt;
&lt;p&gt;After 2 days of digging around for this, and coming up empty handed... I went to the source.. CodePlex.&lt;/p&gt;
&lt;p&gt;I downloaded the source for ASP.NET MVC 2 Futures and did a solution-wide search for RenderAction, and found it in the ViewExtensions class in the Microsoft.Web.Mvc namespace. Formerly, the method signature was Html.RenderAction(&amp;quot;Action&amp;quot;, &amp;quot;Controller&amp;quot;,somethingElseHere)&lt;/p&gt;
&lt;p&gt;Now it seems to require an HtmlHelper object to be passed in as the first argument... so, I&amp;#39;ve found that I needed to call it like this:&lt;/p&gt;
&lt;p&gt;&amp;lt;% ViewExtensions.RenderAction(this.Html, &amp;quot;Menu&amp;quot;, &amp;quot;Nav&amp;quot;, new { highlightCategory = ViewData[&amp;quot;CurrentCategory&amp;quot;] }); %&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Et voila!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=52" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="ASP.NET" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/ASP.NET/default.aspx" /><category term="Visual Studio" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Visual+Studio/default.aspx" /><category term=".net" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/.net/default.aspx" /><category term="MVC 2" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/MVC+2/default.aspx" /></entry><entry><title>How to use the Namespace Alias in .net 3.5</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2009/02/23/how-to-use-the-namespace-alias-in-net-3-5.aspx" /><id>/blogs/clr-programming-blog/archive/2009/02/23/how-to-use-the-namespace-alias-in-net-3-5.aspx</id><published>2009-02-23T19:21:00Z</published><updated>2009-02-23T19:21:00Z</updated><content type="html">&lt;p&gt;Recently in one application I am working on, there was a ambiguous reference between two namespaces.&amp;nbsp; One was an object that was generated by our ORM tool (EntitySpaces), and one that was in the System.Web.Security namespace.&amp;nbsp; The class in both was Roles; a namespace alias was the perfect way to resolve this.&amp;nbsp; Setting a namespace alias is easy, in the using section do this:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; WebSec = System.Web.Security;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then in the code where you have the ambigous reference, just use the WebSec namespace as shorthand like so:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;_groupRoles = _orgManager.GetAccessGroupRoles(groupid,  WebSec.&lt;span style="color:#2b91af;"&gt;Roles&lt;/span&gt;.IsUserInRole(&lt;span style="color:#a31515;"&gt;&amp;quot;SystemAdmin&amp;quot;&lt;/span&gt;));&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;.. and that&amp;#39;s it!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=48" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="C# 2008" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/C_2300_+2008/default.aspx" /><category term="ASP.NET" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/ASP.NET/default.aspx" /><category term="Visual Studio" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Visual+Studio/default.aspx" /><category term=".net" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/.net/default.aspx" /></entry><entry><title>How to set a date format in a gridview control in asp.net</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2009/01/10/how-to-set-a-date-format-in-a-gridview-control-in-asp-net.aspx" /><id>/blogs/clr-programming-blog/archive/2009/01/10/how-to-set-a-date-format-in-a-gridview-control-in-asp-net.aspx</id><published>2009-01-11T02:37:00Z</published><updated>2009-01-11T02:37:00Z</updated><content type="html">&lt;p&gt;Have you ever wanted to display a datetime value in a gridview, with a specific format?&amp;nbsp; It doesn&amp;#39;t always work intuitively because the &amp;lt;asp:BoundField&amp;gt; uses HtmlEncoding by default to prevent cross site scripting ( &lt;a target="_blank" title="MSDN Reference - BoundField HtmlEncode Property " href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode.aspx"&gt;as referenced here&lt;/a&gt; ), so DateTime formatting techniques using the &amp;quot;DataFormatString&amp;quot; attribute of the BoundField will not work.&amp;nbsp; Fixing this is fairly straight forward thoug, all you need to do is either &lt;/p&gt;
&lt;p&gt;1.) Turn off HtmlEncode for the BoundField &lt;/p&gt;
&lt;p&gt;2.) Use&amp;nbsp; &amp;lt;asp:TemplateField&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is an example using the technique to turn the HtmlEncoding off:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;:&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;BoundField&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="text-indent:0.5in;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:red;"&gt;DataField&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;=&amp;quot;EndDate&amp;quot;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;HeaderText&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;End Date&amp;quot;&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;DataFormatString&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{0:M-dd-yyyy}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;span style="color:red;"&gt;HtmlEncode&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is an example using the &amp;lt;asp:TemplateField&amp;gt; method:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;:&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;TemplateField&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt; &lt;span style="color:red;"&gt;HeaderText&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;End Date&amp;quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="text-indent:0.5in;"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;ItemTemplate&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="background:yellow none repeat scroll 0% 0%;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color:blue;"&gt;#&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DateTime&lt;/span&gt;.Parse(Eval(&lt;span style="color:#a31515;"&gt;&amp;quot;EndDate&amp;quot;&lt;/span&gt;).ToString()).ToShortDateString() &lt;span style="background:yellow none repeat scroll 0% 0%;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;"&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;:&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:#a31515;"&gt;TemplateField&lt;/span&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=43" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="C# 2008" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/C_2300_+2008/default.aspx" /><category term="ASP.NET" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/ASP.NET/default.aspx" /><category term="Visual Studio" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Visual+Studio/default.aspx" /><category term=".net" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/.net/default.aspx" /></entry><entry><title>How to access a control on a Master Page from an ASP.NET page using the Master Page</title><link rel="alternate" type="text/html" href="/blogs/clr-programming-blog/archive/2008/11/13/how-to-access-a-control-on-a-master-page-from-an-asp-net-page-using-the-master-page.aspx" /><id>/blogs/clr-programming-blog/archive/2008/11/13/how-to-access-a-control-on-a-master-page-from-an-asp-net-page-using-the-master-page.aspx</id><published>2008-11-13T23:47:00Z</published><updated>2008-11-13T23:47:00Z</updated><content type="html">&lt;p&gt;Today I had to figure out how to access a label control on the masterpage my page was using.&amp;nbsp; It isn&amp;#39;t quite as straightforward as one might imagine, but still not difficult.&amp;nbsp; For this, I am using C# 2008 (v3.5)&lt;/p&gt;
&lt;p&gt;For this particular page, I have an &amp;lt;asp:Label/&amp;gt;&amp;nbsp; control on the line immediately following the &amp;lt;form&amp;gt; tag in the master page. This label is going to be used for displaying general messages, errors, warnings, etc from within the code of pages using it. The problem is that you cannot just do something like &amp;quot;this.Master.FindControl(&amp;quot;LabelDisplay&amp;quot;).Text = &amp;quot;Some Text Here&amp;quot;; (At least not yet).&lt;/p&gt;
&lt;p&gt;To find it you need to walk back up inheritance chain from your present location, to the page that has the control, then find the reference to the target control, cast that reference as the appropriate type (in this particular case Label), then you have access to all of its properties and methods.&lt;/p&gt;
&lt;p&gt;Here is the code to do this:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:&amp;#39;Courier New&amp;#39;;"&gt;((&lt;span style="color:#2b91af;"&gt;Label&lt;/span&gt;)&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Master.Controls[1].Controls[1].FindControl(&lt;span style="color:#a31515;"&gt;&amp;quot;MessageDisplayLabel&amp;quot;&lt;/span&gt;)).Text = &lt;span style="color:#a31515;"&gt;&amp;quot;here we are&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt; &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://strangenut.com/aggbug.aspx?PostID=38" width="1" height="1"&gt;</content><author><name>dacrowlah</name><uri>http://strangenut.com/members/dacrowlah/default.aspx</uri></author><category term="C# 2008" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/C_2300_+2008/default.aspx" /><category term="ASP.NET" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/ASP.NET/default.aspx" /><category term="Visual Studio" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/Visual+Studio/default.aspx" /><category term=".net" scheme="http://strangenut.com/blogs/clr-programming-blog/archive/tags/.net/default.aspx" /></entry></feed>
