<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><description>The name is Roa. Mr. Roa</description><title>Mr. Roa</title><generator>Tumblr (3.0; @mrroa)</generator><link>http://mrroa.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MrRoa" /><feedburner:info uri="mrroa" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://tumblr.superfeedr.com/" /><item><title>ASP .NET MVC &amp; Charting</title><description>&lt;p&gt;At some point in our career as Web developers we’ve been asked to add a visual representation of data, commonly known as charts. Charting is an integral part of a line of business application. They represent data in a subtlety manner, making easier to interpret compiled data and make decisions from it. A chart can take a large variety of forms, however there are common features that provide the chart with its ability to extract meaning from data.&lt;/p&gt;
&lt;p&gt;There are many options to render data on your Web application depending on your needs. We are going to discuss some of the options and see an example of how to do it on an ASP .NET MVC project. This might help us choose from the overwhelming offer of free components out there.&lt;/p&gt;
&lt;h3&gt;Doesn’t Microsoft provide free charting tools?&lt;/h3&gt;
&lt;p&gt;The answer is &lt;strong&gt;YES&lt;/strong&gt;, but they are available as server-side controls for ASP .NET Webforms. After Microsoft acquiring Dundas Software, a couple of years ago, they where introduced on the previous .NET framework release (v3.5) and made formally part of the framework on the latest release (v4.0). Scott Guthrie describes the control in &lt;a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx"&gt;this&lt;/a&gt; blog post.&lt;/p&gt;
&lt;p&gt;Certainly this charting control can be incorporated into ASP .NET MVC with ease. There’s been a lot of &lt;a target="_blank" href="http://stackoverflow.com/questions/319835/new-aspnet-charting-controls-will-they-work-with-mvc-eventually#320891"&gt;discussion&lt;/a&gt; about ways of achieving this. The solution boils down to just needing to reference the DataVisualization assembly and the handler for rendering the chart image on the web.config.&lt;/p&gt;
&lt;p&gt;But doesn’t this feel a little out of place? Specially for the purpose of this framework? It’s like all of the sudden Mr. Postback is right around the corner of becoming a special needed feature of your ASP .NET MVC application. Ironic isn’t it? &lt;/p&gt;
&lt;h3&gt;Other options in the charting world&lt;/h3&gt;
&lt;p&gt;Parting from this, many options exist, in order to fulfill this “must have” requirement. There are many flavors to choose from, when it comes to free charting libraries. Just to mention a few: Google Charting Tools, amCharts, Open Flash Charts, Flot, JSCharts…&lt;/p&gt;
&lt;h4&gt;Breaking them down!&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://code.google.com/apis/charttools/"&gt;Google Charting Tools&lt;/a&gt; are a good option. They’re pretty straight forward to use and understand. Google also provides a visualization playground where you can get more intimate with the API and all its features.&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://code.google.com/p/flot/"&gt;Flot&lt;/a&gt; is a jQuery plugin simple to use and renders awesome looking charts.  If you’re used to working with jQuery, this will be heaven for you. It displays a wide variety of charting options and programming utilities like feedback of the points clicked on the chart area. Go grab it now!&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://www.amcharts.com/"&gt;amCharts&lt;/a&gt; its a fancy looking solution. They have a huge palette of options for rendering data. Their charts also can have animations. If you want to use these you have to be willing to get your hands dirty in order to get this beast tamed. These charts are highly configurable, therefore you have to work with to separated XML files to get them working: one for the data and one for the chart configuration.&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://teethgrinder.co.uk/open-flash-chart-2/"&gt;Open Flash Chart&lt;/a&gt; now this is the FULL package, it has it all. It renders the charts in flash but embraces the use of JSON as the data file, which makes them a perfect candidate for JavaScript tweaking. Also being completely open source, like Flot, encourages developers to create libraries and extend their functionality. There’s a library built for .NET already available for download on the linked site.&lt;/p&gt;
&lt;h3&gt;Isn’t this a technical blog?! Show me some code!!!!!&lt;/h3&gt;
&lt;p&gt;Just to be coherent, After praising Open Flash Charts, I’m choosing this package to feature on my example.&lt;/p&gt;
&lt;p&gt;In order to start, let’s be clear on what we need:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Open Flash Chart swf object.&lt;/li&gt;
&lt;li&gt;A library that can write JSON. (Open Flash Chart .NET library preferably, just to avoid the wheel reinvention) &lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;And that’s it!!!&lt;/p&gt;
&lt;p&gt;So let’s start by getting the whole thing from the Open Flash Chart’s site &lt;a target="_blank" href="http://teethgrinder.co.uk/open-flash-chart-2/downloads.php"&gt;download&lt;/a&gt; section. This will provide us with the charts swf object and different libraries for different languages and implementations.&lt;/p&gt;
&lt;p&gt;After unpacking your download go straight to the “dot-net-library” directory and extract the DLL from the “OpenFlashChart” library project. If you want, you can open the solution and run the test website where you can see implementations of all the available options.&lt;/p&gt;
&lt;p&gt;So following the tutorial we need to embed the OpenFlashChart.swf object to our webpage. To do so I chose the swfObject JavaScript library, which can be imported to the desire view or the site’s master page from Google’s CDN.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"&gt;&lt;/script&gt;&lt;/pre&gt;
&lt;p&gt;After importing the swfobject library we just need to embed our flash object like this:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;script type="text/javascript"&gt;
     swfobject.embedSWF("open-flash-chart.swf", "my_chart", "250", "200", "9.0.0");
&lt;/script&gt;
&lt;/pre&gt;
&lt;p&gt;This &lt;a target="_blank" href="http://teethgrinder.co.uk/open-flash-chart-2/tutorial-3.php"&gt;tutorial&lt;/a&gt; shows how data can be passed to the chart using a data file explicitly instead of using the query-string which is the default way of specifying the file.&lt;/p&gt;
&lt;p&gt;Instead of using that code directly on our views I’d rather use another approach, which consists on creating a Html helper to render the chart. I’ve gone ahead and created a static extension class in order to extend the ASP .NET MVC’s Html Helper, here’s the code for my method.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;#region OpenFlashChart
public static string RenderChart(this HtmlHelper helper, 
  string chartContainer, //This is the id of the html container where the chart is going to be rendered preferably a div.
  string chartData, //This is the route to the chart JSON formatted data
  int width, //This is the chart width
  int height, //This is the chart height
  string loadingText = "Loading data...") //This is chart's the loading text
{            
            var chart = new StringBuilder();

            //Creating the script tag
            var script = new TagBuilder("script");

            //Adding the type attribute
            script.Attributes.Add("type", "text/javascript");

            //Setting the swf object definition for the open flash chart
            string swfobject = "swfobject.embedSWF(" +
                        "\"/Content/swf/open-flash-chart.swf\"," + //This can be set from a config file or w/e
                        "\""+ chartContainer +"\"," + 
                        "\""+ width +"\"," + 
                        "\""+ height +"\"," +
                        "\"9.0.0\"," + 
                        "\"/Content/swf/expressInstall.swf\"," +
                        "{ \"data-file\": \""+ chartData +"\", \"loading\":\"" + loadingText + "\" }" +
                    ");";

            //Setting the inner text of the script tag without HTML encoding
            script.InnerHtml = swfobject;
            
            //Appending the script tag to the helper result
            chart.Append(script);

            //Returning the open flash chart client code implementation
            return chart.ToString();
}
#endregion
&lt;/pre&gt;
&lt;p&gt;Now that we have our helper to render the chart it’s time to copy the corresponding files. First move the open-flash-chart.swf to the Content/swf directory as well as the flash expressInstall file. And then add a reference to the extracted OpenFlashChart library.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/importdll.png" alt="import dll"/&gt;&lt;/p&gt;
&lt;p&gt;So now we are half way through, we just need to things: a controller method that returns the JSON formatted data and the implementation of our helper on the desired view.&lt;/p&gt;
&lt;p&gt;I created a new controller called ExampleController which contains a method called Chart, which is responsible of generating the chart’s random data an returning the JSON formatted info in order to render the chart.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;public string Chart()
{
            //Populating random chart data
            var chartData = new List();
            var rand = new Random(DateTime.Now.Millisecond);
            for (double i = 0; i &lt; 12; i++)
            {
                chartData.Add(rand.Next(30));
            }


            //Creating the chart type definition
            Area area = new Area
                            {
                                Values = chartData,
                                HaloSize = 0,
                                Width = 2,
                                DotSize = 5,
                                FontSize = 12,
                                DotStyleType =
                                    {
                                        Tip = "#x_label#&lt;br /&gt;#val#",
                                        Type = DotType.DOT,
                                        Colour = "#467533"
                                    },
                                Tooltip = "#val#",
                                Colour = "#CC3399",
                                FillColor = "#343399",
                                FillAlpha = .5
                            };

            //Creating the chart object
            var chart = new OpenFlashChart.OpenFlashChart { Title = new Title("line chart") };

            //Setting the Y axis properties
            chart.Y_Legend = new Legend("y axis");
            chart.Y_Axis.SetRange(0, 35, 5);
            chart.Y_Axis.Steps = 3;

            //Setting the X axis properties
            chart.X_Axis.Labels.Color = "#e43456";
            chart.X_Axis.Steps = 4;

            //Defining the chart's tooltip properties
            chart.Tooltip = new ToolTip("#val#")
                                {
                                    Shadow = true,
                                    Colour = "#e43456",
                                    MouseStyle = ToolTipStyle.CLOSEST
                                };
            
            //Adding the chart type to the elements collection of the chart
            chart.AddElement(area);

            //The library has a built in JSON serializer
            return chart.ToPrettyString();
}&lt;/pre&gt;
&lt;p&gt;Now we just need to call our Html helper extension method from the view to render the chart like this.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;%= Html.RenderChart("chartContainer", "example/chart", 960, 180) %&gt;
&lt;/pre&gt;
&lt;h3&gt;Voila! We’ve got a nice looking chart!&lt;/h3&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/chart.png" alt="chart"/&gt;&lt;/p&gt;
&lt;p&gt;Try reading the tutorials listed on the Open Flash Chart web page where you can learn how to customize the its elements.&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;All these charting tools are useful and get the job done. They provide us with a set of tools to achieve the data visualization need of our clients. It’s your job to choose the one that suits better your needs. &lt;/p&gt;
&lt;p&gt;Taking into account this drawback, having JavaScript disabled on the browser might be a killer for some of the animated charts. This is an inherited issue for all the Google charting tools siblings which rely on client-side rendering like &lt;a target="_blank" href="http://code.google.com/p/flot/"&gt;Flot&lt;/a&gt; or &lt;a target="_blank" href="http://www.jscharts.com/"&gt;JSCharts&lt;/a&gt;. This is where the ASP .NET chart control wins the fight.&lt;/p&gt;
&lt;p&gt;I don’t know if there’s a successful web application that doesn’t embrace the power of JavaScript, but there are some IE6 users who work for corporations where the IT department don’t like JavaScript. I guess these poor people don’t know what they’re missing!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://s.mrroa.com/Charting.zip"&gt;Download&lt;/a&gt; the source code.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=X46e_MFqr5Y:_RIntctctwM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=X46e_MFqr5Y:_RIntctctwM:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=X46e_MFqr5Y:_RIntctctwM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=X46e_MFqr5Y:_RIntctctwM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=X46e_MFqr5Y:_RIntctctwM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=X46e_MFqr5Y:_RIntctctwM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MrRoa/~4/X46e_MFqr5Y" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/MrRoa/~3/X46e_MFqr5Y/7761615922</link><guid isPermaLink="false">http://mrroa.com/post/7761615922</guid><pubDate>Fri, 20 Aug 2010 00:00:00 -0400</pubDate><category>aspnetmvc</category><category>charting</category><feedburner:origLink>http://mrroa.com/post/7761615922</feedburner:origLink></item><item><title>TIP/Trick: Use DataPager control with ListView and Custom Data Source</title><description>&lt;p&gt;Paging tabular data retrieved through a database query has been a long time need in transactional line of business applications. With time the ways of achieving this in ASP .NET have evolved into very easy solutions. On the previous version of the framework, .NET framework 3.5 (currently to the date they are now on 4.0) two server-side user controls where introduced, the ListView and the DataPager.&lt;/p&gt;
&lt;p&gt;They idea behind the ListView control is to provide the developer with more control over the markup output while providing the data-bound experience of previous controls. The ListView control displays data based on user defined templates, which is extremely convenient for styling purposes. It also reduces to zero the garbage markup automatically generated by older controls like the GridView.&lt;/p&gt;
&lt;p&gt;The DataPager, in the other hand, is product of the decoupling of the paging feature from the data-bound controls that implement the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.ipageableitemcontainer.aspx"&gt;IPageableItemContainer&lt;/a&gt; interface. Providing more freedom when it comes to paging customization on regards of functionality and appearance.&lt;/p&gt;
&lt;p&gt;Both controls complement each other in a marvelous way. The DataPager provides paging practically out of the box when using a data source control, which is what the documentation found almost everywhere encourages to use. BUT! The truth is that sometimes we use custom data sources because of a special scenario that dictates their use to get the data. In this scenario is were the use of the DataPager becomes a little bit more challenging, since the paging is once more a developer’s responsibility rather than a delegated feature for the framework.&lt;/p&gt;
&lt;h3&gt;So how do we tackle this?&lt;/h3&gt;
&lt;p&gt;One approach is raising and handling the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatepagerfield.pagercommand.aspx"&gt;PagerCommand&lt;/a&gt; event found on the DataPager &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatepagerfield.aspx"&gt;TemplatePagerField&lt;/a&gt; template and evaluating each command sent from the server-side controls placed there. This is extremely convenient if you want to implement a custom way of paging the data and navigating through it. You’ll also have the responsibility of rendering the current page you’re at, as well as all the other available navigation pages.&lt;/p&gt;
&lt;p&gt;Another approach, and the one we’ll describe with more depth, is a little bit more simple and similar to the default behavior of the DataPager when used with data source controls. For this we just need to raise the ListView’s &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.pagepropertieschanging.aspx"&gt;PagePropertiesChanging&lt;/a&gt; event and invoke the DataPager’s &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datapager.setpageproperties.aspx"&gt;SetPageProperties&lt;/a&gt; method. This is an obvious combination since the PagePropertiesChangingEventArgs provide us the arguments of the SetPageProperties method overload.&lt;/p&gt;
&lt;h3&gt;The code&lt;/h3&gt;
&lt;p&gt;I think we’ve done enough to describe what we are trying to achieve here, so let’s see the code for this. Let’s asume we have a ListView called lvProducts.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;protected void lvProducts_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
    var pager = (DataPager)lvProducts.FindControl("pager"); //pager is the name of our DataPager control

    pager.SetPageProperties(

      e.StartRowIndex, 

      e.MaximumRows, 

      false); //Set false because we are using a custom data source

    BindDataToListView(); //Here we just bind the data to our list view again and the new data page will be displayed
}&lt;/pre&gt;

&lt;p&gt;And that’s it! Paging should work like a charm. Happy coding!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=ESPC3aZuaP4:Ns5gVaWzP1A:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=ESPC3aZuaP4:Ns5gVaWzP1A:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=ESPC3aZuaP4:Ns5gVaWzP1A:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=ESPC3aZuaP4:Ns5gVaWzP1A:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=ESPC3aZuaP4:Ns5gVaWzP1A:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=ESPC3aZuaP4:Ns5gVaWzP1A:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MrRoa/~4/ESPC3aZuaP4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/MrRoa/~3/ESPC3aZuaP4/7761510232</link><guid isPermaLink="false">http://mrroa.com/post/7761510232</guid><pubDate>Tue, 20 Jul 2010 00:00:00 -0400</pubDate><category>tips</category><category>data-pager</category><feedburner:origLink>http://mrroa.com/post/7761510232</feedburner:origLink></item><item><title>How to use Membership/Role Provider and when to use custom implementations</title><description>&lt;p&gt;Authentication is a must have feature for every system. Every system administrator needs to give an identity to the ones using their system. Which leads us, developers, to make this repetitive process something easier to implement and reuse every now and then on any application that may need user login.&lt;/p&gt;
&lt;p&gt;I’ve seen many “authentication frameworks” which encapsulate simple verification routines into assemblies, that can be implemented as easy as just creating a reference and running a sql script against the DB. What the heck! Even I made one of those and felt 1337 because of my glorious creation. But! That was until I meet the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms972319.aspx"&gt;provider model&lt;/a&gt;, which reduced the greatness of my crappy “framework” or I may say, reinvention of the wheel.&lt;/p&gt;
&lt;p&gt;The provider model involves many other things that go a lot further than just user authentication, resource permissions, etc. For now I’ll address the ones related to user management and their default implementation.&lt;/p&gt;
&lt;h3&gt;What? More sh*!t about Membership/Role/Profile Provider?!! Why should I care?&lt;/h3&gt;
&lt;p&gt;Let’s start by saying that this is not something new. The provider model has been around since ASP .NET 2.0, therefore 5 years ago you could’ve done this without any problem the same way I’m gonna do it now. The deal is that people rather read or download an example from a blog, than actually spend some time reading about how the thing works and what’s the most suitable way of implementing it
&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;
depending t
&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;
heir given situation.&lt;/p&gt;
&lt;p&gt;Instead of trying to write a manual of how to do it, I’ll try to explain why use the default or simplest form of the provider model for user management rather than opting for a custom membership provider. Of course if you are able to choose how to handle your users and you don’t stick an existing form of user authentication into your app. Either way I encourage you to drop your &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Leet"&gt;1337&lt;/a&gt; implementation, and use this since the Login controls work out of the box.&lt;/p&gt;
&lt;p&gt;My intention is to eradicate the taboo surrounding t
&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;
his, and really show how simple it is to make this work along with our application without any effort at all.&lt;/p&gt;
&lt;h3&gt;To Customize the provider or not to customize the provider&lt;/h3&gt;
&lt;p&gt;So, in order to make the provider a viable solution they had to make it flexible. And it is. By simply extending the membership, role or provider base classes you can implement your own customization of these providers. The thing is that people tend to opt for this without hesitating falling again into the loop of reinventing something that it’s already done for you.&lt;/p&gt;
&lt;p&gt;Everything resumes to this: Unless you have to use a pre-defined structure for the users database your option will be a custom implementation of the membership/role/profile providers. But if you are using ASP .NET 2.0 or higher (obviously), MSSQL, and do not have to use an existing user base you shouldn’t create your custom provider. There are also ports of the ASP .NET Application Services DB for Oracle, MySQL and Postgre, so there are not excuses for this.&lt;/p&gt;
&lt;p&gt;The usual excuse for resistance of using the default implementation of the provider is the assumption of “having to rely on the username field and having alphanumeric fields as FK’s among the whole system might affect performance”. This, even though it sounds technically convincing it’s a lie. All the relationships on the default DB schema are made using GUID’s which definitely knock off this vague excuse. Obtaining the user’s unique identifier takes as little as two lines of code, so don’t let that stop you.&lt;/p&gt;
&lt;p&gt;Avoiding the implementation of a custom membership/role/profile provider WILL save you time and let you focus on other tasks more important than user administration and resource permissions.&lt;/p&gt;
&lt;h3&gt;OK, so where’s the code?&lt;/h3&gt;
&lt;p&gt;Since I’m not addressing a custom implementation of any of the providers being discussed. It’s only going to be necessary to configure the providers using the web.config or the ASP .NET Configuration panel. There are a couple of ways of implementing the membership and role provider on its simplest form. One way is to use the ASP .NET Configuration in order to achieve it. Let’s see how.&lt;/p&gt;
&lt;h4&gt;Step 1&lt;/h4&gt;
&lt;p&gt;First, select the ASP .NET Configuration option from your Website menu in Visual Studio.&lt;/p&gt;
&lt;p&gt;&lt;img height="460" width="700" alt="ASP .NET Configuration" src="http://s.mrroa.com/membershipstep1a.png"/&gt;&lt;/p&gt;
&lt;p&gt;Note that this will open a website which contains the website configuration settings grouped in three categories: Security, Application Configuration &amp; Provider Configuration.These presented options on the ASP .NET Configuration website will allow us to configurate everything, from authentication methods, users and all that other stuff to smtp mail servers (of course this is useful if our application sends emails, for instance a user password reset). Here’s what you can do on each tab:&lt;/p&gt;
&lt;p&gt;Security.- Here you’ll be able to find the user/role configuration stuff, you’ll be able to do CRUD operations on your users and roles, and also define the access rules per user/role for your application resources.&lt;/p&gt;
&lt;p&gt;Application Configuration.- Here, you can define application settings which are just application are keys that are going to be accessible from the &lt;appSettings/&gt; dictionary. Also you’ll be able to set the stmp settings, take the application offline and set the debugging and tracing options.&lt;/p&gt;
&lt;p&gt;Provider Configuration.- Here, you can select the providers you’ll on the application, these is very useful since you can define various providers on your web.config (if you’d like) and switch through them. For instance the settings for your application on the development environment are different from your production environment.&lt;/p&gt;
&lt;p&gt;&lt;img height="460" width="700" alt="ASP .NET Configuration" src="http://s.mrroa.com/membershipstep1b.png"/&gt;&lt;/p&gt;
&lt;p&gt;Also, this action will automatically create a new Database file and place it on your App_Data folder of your website/webapp. This database named aspnetdb will contain the Application Services DB schema definition.&lt;/p&gt;
&lt;p&gt;&lt;img height="460" width="700" alt="ASP .NET Application Services DB" src="http://s.mrroa.com/membershipdb.png"/&gt;&lt;/p&gt;
&lt;h4&gt;Step 2&lt;/h4&gt;
&lt;p&gt;You just need to access the Security tab and start creating your users, roles and access rules.&lt;/p&gt;
&lt;p&gt;&lt;img height="460" width="700" alt="ASP .NET Application Services DB" src="http://s.mrroa.com/membershipstep2.png"/&gt;&lt;/p&gt;
&lt;p&gt;By default we have in our hands a simple yet robust implementation of user management. We are able to select the forms of authentication for our application from the provided configuration options, Windows or Forms, these options are described on the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ff359131.aspx"&gt;msdn documentation&lt;/a&gt;. When using forms authentication, the passwords of our users are going  to stored on our database, by default these are going to be hashed.  Also our users need to have a secret question/answer in order to  reset/retrieve their passwords.&lt;/p&gt;
&lt;p&gt;From our application will be able  to access all of these user  management CRUD actions by using the  System.Security.Membership class.  All of the Login Toolbox controls  located on the visual studio Toolboox  palette, will work without  writting a single line of code.&lt;/p&gt;
&lt;h3&gt;Great! But what if I want to use my own Database&lt;/h3&gt;
&lt;p&gt;So you already have designed your application database and you want  include the Application Services Schema definition in it. This is a very  common scenario, and you’ll need to do very little to get this working.&lt;/p&gt;
&lt;p&gt;First, you need to run the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/x28wfk74.aspx"&gt;aspnet_regsql&lt;/a&gt; command from the visual studio command prompt and go through the, fairly simple, wizard  until you select and register your database. This will copy all the Application Services tables and store procedures that you’ll need to use the Provider Model into your existing DB.&lt;/p&gt;
&lt;p&gt;After that, you’ll need to define a connection string that points to that database on your web.config. This connection string will be specified on our membership provider definition.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;remove name="LocalSqlServer"/&gt;
&lt;add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyAppDB;Persist Security Info=True;&lt;br/&gt;User=sa;Password=P@$$w0rd" providerName="System.Data.SqlClient"/&gt;&lt;/pre&gt;
&lt;p&gt;Now we just need to define the provider and then change the membership provider for the application to use our new one on the Provider Configuration.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;system.web&gt;  
   &lt;membership userIsOnlineTimeWindow="20" hashAlgorithmType="SHA1"&gt;
      &lt;providers&gt;
        &lt;add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"
          enablePasswordReset="true" requiresQuestionAndAnswer="false"
          passwordFormat="Hashed" applicationName="MyApplication" name="MyAppMembershipProvider"
          type="System.Web.Security.SqlMembershipProvider" /&gt;
      &lt;/providers&gt;
   &lt;/membership&gt;
&lt;/system.web&gt;
&lt;/pre&gt;
&lt;h3&gt;Retrieving the User Unique Identifier&lt;/h3&gt;
&lt;p&gt;If you need to create a relationship between a user and any other entity by using it’s unique identifier (GUID) instead of its username, you just need to retrieve it by using the read-only property ProviderUserKey from the MembershipUser class.&lt;/p&gt;
&lt;pre class="prettyprint"&gt;System.Web.Security.MembershipUser mu = System.Web.Security.Membership.GetUser();&lt;br/&gt;string usrID = mu.ProviderUserKey.ToString();&lt;/pre&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;On this blog post, I discussed ASP .NET Membership &amp; Role provider  implementations on it’s simplest form, which in my opinion should be your  first option when implementing this feature, of course if the scenario allows  it. Custom implementation of the providers aren’t bad and I’m not  against them but you should use them when its necessary, that’s all. This topic was very debated when this feature first came out, and &lt;a target="_blank" href="http://www.4guysfromrolla.com/articles/120705-1.aspx"&gt;4 Guys from  Rolla&lt;/a&gt; have a very good series of articles that go in depth on the  subject, I encourage you to read it if you are interested on learning  how this thing works.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=aA7HZqODyjU:QcKG5vn5Vi8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=aA7HZqODyjU:QcKG5vn5Vi8:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=aA7HZqODyjU:QcKG5vn5Vi8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=aA7HZqODyjU:QcKG5vn5Vi8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=aA7HZqODyjU:QcKG5vn5Vi8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=aA7HZqODyjU:QcKG5vn5Vi8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MrRoa/~4/aA7HZqODyjU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/MrRoa/~3/aA7HZqODyjU/7751062378</link><guid isPermaLink="false">http://mrroa.com/post/7751062378</guid><pubDate>Sun, 28 Feb 2010 00:00:00 -0500</pubDate><category>membership</category><category>provider model</category><feedburner:origLink>http://mrroa.com/post/7751062378</feedburner:origLink></item><item><title>TIP/Trick: Enable/Disable ASP .NET Ajax TabContainer Tabs</title><description>&lt;p&gt;Space and content distribution is a very important part when designing a web site. That’s why breaking content into multiple sections using a tabbed widget in order to save space is a commonly used technique in web design these days.&lt;/p&gt;
&lt;p&gt;Today I’m going to address a common issue that arises when using a tab widget, which is enabling/disabling specific tabs. But first let’s talk a little bit about the &lt;a target="_blank" href="http://www.asp.net/ajax/AjaxControlToolkit/Samples/"&gt;Ajax Control Toolkit&lt;/a&gt;. The Ajax Control Toolkit provides a palette of AJAX enabled controls, with the purpose of creating an “interactive web experience”. If you work with ASP .NET, you MUST have heard about &lt;a target="_blank" href="http://www.asp.net/ajax/"&gt;ASP .NET AJAX&lt;/a&gt;, previously known as ATLAS. You must also have seen and feel familiar with update panels and Microsoft’s ASP .NET AJAX paradigm. Certainly the ASP .NET AJAX framework makes AJAX implementation trivial to anyone.&lt;/p&gt;
&lt;p&gt;The tendency of throwing update panels everywhere in order to achieve partial post backs in your page it’s a widely used approach among ASP .NET AJAX enabled sites. It’s also a common practice to see how every server/client side control on a web page, get replaced with any equivalent found on the AJAX Toolkit provided by Microsoft. If you are using one of these “cutting edge” techniques my friend, let me tell you that you are killing your application performance. And that also, I’m NOT the first one to point this out. The ASP .NET AJAX framework and the AJAX Toolkit have been widely criticized over thousands of technical web blogs. Mainly because by providing a mechanism for “easy” AJAX implementation performance of your web application gets compromised.&lt;/p&gt;
&lt;p&gt;Basically, performance get
&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;
s affected because a lot of web resources get imported when using both the framework and the toolkit. Also the fact that in every “partial post back” you actually send the whole page making HTTP GET/POST actions more bloated when loading your page. You could use Mozilla Firefox’s Firebug plugin to analyze your HTTP requests and the amount of data that gets sent back and forth to the server, or just google about the topic in order to extend your knowledge about this particular subject.&lt;/p&gt;
&lt;p&gt;I encourage you guys to use other lightweight javascript frameworks that help you achieve DOM manipulation and asynchronous calls to the server in order to retrieve and send data like &lt;a target="_blank" href="http://www.jquery.com/"&gt;jQuery&lt;/a&gt; or &lt;a target="_blank" href="http://www.prototypejs.org/"&gt;Prototype&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Show me the code!&lt;/h3&gt;
&lt;p&gt;So I decided to do two examples instead of one. Besides doing it using the AJAX Control Toolkit. I also did it using jQuery, just to have two options. So here’s the code.&lt;/p&gt;
&lt;h4&gt;AJAX Control Toolkit Tab Container&lt;/h4&gt;
&lt;p&gt;Here’s the HTML:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;div style="width: 500px"&gt;
  &lt;cc1:TabContainer ID="TabContainer1" runat="server"&gt;
      &lt;cc1:TabPanel Hea&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;!--mce:2--&gt;&lt;/script&gt;derText=”Tab 1” runat=”server” ID=”tpTab1”&gt;
          &lt;ContentTemplate&gt;
                Tab 1 Content!
          &lt;/ContentTemplate&gt;
      &lt;/cc1:TabPanel&gt;
      &lt;cc1:TabPanel HeaderText=”Tab 2” runat=”server” ID=”tpTab2”&gt;
          &lt;ContentTemplate&gt;
                Tab 2 Content!
          &lt;/ContentTemplate&gt;
      &lt;/cc1:TabPanel&gt;
  &lt;/cc1:TabContainer&gt;
  &lt;p&gt;
      &lt;input type=”button” onclick=”javascript:DisableEnableTab(false,0);” value=”Disable Tab 1” /&gt;
  &lt;/p&gt;         
&lt;/div&gt;
&lt;/pre&gt;
&lt;p&gt;And here’s the javascript:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;function DisableEnableTab(boolVal, tabIndex) {
      var tab = $find('&lt;%=TabContainer1.ClientID%&gt;');
      tab.get_tabs()[tabIndex].set_enabled(boolVal);
}
&lt;/pre&gt;
&lt;h3&gt;jQuery&lt;/h3&gt;
&lt;p&gt;Here’s the HTML:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;&lt;div id="tabs" style="width: 500px"&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="#tab-1"&gt;&lt;span&gt;One&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#tab-2"&gt;&lt;span&gt;Two&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
      &lt;div id="tab-1"&gt;
          Tab 1 Content!
      &lt;/div&gt;
      &lt;div id="tab-2"&gt;
          Tab 2 Content!
     &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
   &lt;input type="button" onclick="javascript:DisableTab();" value="Disable Tab 1" /&gt;
&lt;/p&gt;
&lt;/pre&gt;
&lt;p&gt;And here’s the javascript:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;$(document).ready(function() {
      $("#tabs").tabs();
 });
            
 function DisableTab() {
       //Selecting another tab
      $("#tabs").tabs('select', 1);
                
      //Disabling first tab
      $("#tabs").tabs('option', 'disabled', [0]);
 }
&lt;/pre&gt;
&lt;p&gt;So there it is, happy coding!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=Pibz2bYaSNM:I87EwF90_Kc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=Pibz2bYaSNM:I87EwF90_Kc:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=Pibz2bYaSNM:I87EwF90_Kc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=Pibz2bYaSNM:I87EwF90_Kc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=Pibz2bYaSNM:I87EwF90_Kc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=Pibz2bYaSNM:I87EwF90_Kc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MrRoa/~4/Pibz2bYaSNM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/MrRoa/~3/Pibz2bYaSNM/7750990857</link><guid isPermaLink="false">http://mrroa.com/post/7750990857</guid><pubDate>Tue, 01 Dec 2009 00:00:00 -0500</pubDate><category>tips</category><category>jQuery</category><category>AJAX</category><category>tabs</category><feedburner:origLink>http://mrroa.com/post/7750990857</feedburner:origLink></item><item><title>Can URI and URL be used interchangeably ?!</title><description>&lt;p&gt;Have you encountered yourselves hesitating when trying to use the terms URI or URL? I have. Apparently the difference between a URI and a URL is a very debated topic on the web. And it’s also a source of confusion for many people, including myself.  &lt;/p&gt;
&lt;p&gt;Almost every comparison that I find seem to be a tongue-twister, which vaguely describes that they are related but they’re not the same (aha! you see? I did it too, I said something but actually said nothing. PLOP!). The truth is that there’s a different RFC describing the scheme of each, URI’s and URL’s. If you go through the W3C documentation you’ll find that they have a &lt;a target="_blank" href="http://www.w3.org/TR/uri-clarification/"&gt;documentation page&lt;/a&gt; trying to clarify the confusion around URI’s.&lt;/p&gt;
&lt;h3&gt;In the end? What’s are URI’s and what are URL’s?&lt;/h3&gt;
&lt;p&gt;The &lt;a target="_blank" href="http://www.ietf.org/rfc/rfc2396.txt"&gt;RFC2396&lt;/a&gt; describes a Uniform Resource Identifier (URI) as a set of characters used to identify a resource name, location or both on the internet. This means that an URI can be classified as a locator (URL), a name (URN), or both. The &lt;a target="_blank" href="http://tools.ietf.org/html/rfc2717"&gt;RFC2717&lt;/a&gt; describes a “Uniform Resource Locator” (URL) as a compact string representation of the location for a resource that is available via the Internet. Parting from these definitions we can conclude that every time we refer to a URL we are talking about an URI, but not the other way.&lt;/p&gt;
&lt;h3&gt;So? Can we use them interchangeably?&lt;/h3&gt;
&lt;p&gt;The short answer is, NO. Even though its a tendency among experts, &lt;a target="_blank" href="http://tools.ietf.org/html/draft-mealling-uri-ig-00"&gt;this&lt;/a&gt; World Wide Web Consortium memo states that there shouldn’t be any confusion, since they all have different schemes (URI’s, URL’s and URN’s) describing the differences among them. BUT!!! If we are talking about “how to identify the resource and provide the means of locating the resource by describing it’s primary access mechanism” then we are talking about an URL, which is also an URI; therefore we can use them interchangeably in that specific case.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;When talking about Internet resources we tend to use these terms to refer to them, specially when talking about HTTP actions in order to get a document. So, there’s always the safe way of doing things: if you don’t know if you are talking an URL or an URI, just
&lt;script type="text/javascript" src="../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;
refer to it as an URI and you wont be wrong.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=1pEoPLURE7U:WDgd3slxhJo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=1pEoPLURE7U:WDgd3slxhJo:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=1pEoPLURE7U:WDgd3slxhJo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=1pEoPLURE7U:WDgd3slxhJo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=1pEoPLURE7U:WDgd3slxhJo:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=1pEoPLURE7U:WDgd3slxhJo:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MrRoa/~4/1pEoPLURE7U" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/MrRoa/~3/1pEoPLURE7U/7750794454</link><guid isPermaLink="false">http://mrroa.com/post/7750794454</guid><pubDate>Wed, 28 Oct 2009 00:00:00 -0400</pubDate><category>URN</category><category>URL</category><category>URI</category><category>WWW</category><category>W3C</category><feedburner:origLink>http://mrroa.com/post/7750794454</feedburner:origLink></item><item><title>How to: Write your own Visual Studio Code Snippets</title><description>&lt;p&gt;Just to go with the formality flow, let’s first define a snippet. According to &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Code_snippets"&gt;wikipedia,&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt;a&lt;strong&gt; Code Snippet&lt;/strong&gt; is a programming term for a small region of re-usable source code or text. Ordinarily, these are formally-defined operative units to incorporate into larger programming modules. Snippets are often used to clarify the meaning of an otherwise “cluttered” function, or to minimize the use of repeated code that is common to other functions.&lt;/p&gt;
&lt;p&gt;Visual studio allows us to add our own code snippets for reuse of common block codes in current or further projects. Custom code snippets can be adhered to the ones bundled with the IDE. These can be created and edited with the text editor of your preference. Snippets are handled as XML files, which follow a &lt;a title="Code Snippet XML Schema" target="_blank" href="http://msdn.microsoft.com/en-us/library/ms171418.aspx"&gt;XML Schema&lt;/a&gt; from Microsoft. This schema contains the definition of mandatory elements and attributes for the snippet to work.&lt;/p&gt;
&lt;p&gt;Since the 2005 release, code snippets were introduced as part of Visual Studio. Visual Studio 2005/2008 itself has pre-bundled snippets for surrounding or inserting code blocks. Visual Studio also allows code snippets to be added to the toolbar by simply pasting the code block into it. You could create different tabs to classify them.&lt;/p&gt;
&lt;h3&gt;How to create your own custom code snippet in Visual Studio 2005/2008&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; To start, let’s create an XML file with a *.snippet extension. This file will contain our snippet attributes, as well as the desired code block.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/codesnippetsstep1.PNG"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Ironically, let’s use the “snippet” snippet which comes pre-bundled with Visual Studio. This will inject into our file the snippet XML structure.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/codesnippetsstep2.PNG"/&gt;&lt;/p&gt;
&lt;p&gt;3. Edit the snippet template by filling in the necessary values.The type for the snippets may vary depending on what we want to achieve, we may only want to insert a block code, or surround one with the desired snippet as well. The declarations correspond to de variables that may be edited from the code edit
&lt;script type="text/javascript" src="http://www.mrroa.com/Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js"&gt;&lt;/script&gt;
or (Visual Studio) and they must be referred between $ on the code element. We must specify for what language is the snippet as well.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/codesnippetsstep3.PNG"/&gt;&lt;/p&gt;
&lt;p&gt;4. After editing the file, the next step is to open the Code Snippets Manager from the tools menu. On the Code Snippets Manager by selecting add, we are going to be able to add a complete folder containing our code snippets. If we want to import one specific snippet into a selected folder we just have to click on Import.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/codesnippetsstep4.PNG"/&gt;&lt;/p&gt;
&lt;h3&gt;Using our custom code snippet&lt;/h3&gt;
&lt;p&gt;So let’s use our code snippet. We can select it from the insert code snippet in the Visual Studio context menu (right click on the class file), or we can use our defined shortcut and press tab twice to import the block of code.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/codesnippetsstep5.PNG"/&gt;&lt;/p&gt;
&lt;h3&gt;The Result!&lt;/h3&gt;
&lt;p&gt;So here it is ladies and gentlemen, our custom code snippet!&lt;/p&gt;
&lt;p&gt;&lt;img src="http://s.mrroa.com/codesnippetsstep6.PNG"/&gt;&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;The purpose of this article is to highlight a very useful feature from Microsoft’s IDE. A cool feature we should exploit in order to gain the most of it, and that not many people gets to take advantage of. Grabbing a code block that is constantly reused and insert it from with the help of the IDE whenever we need it, boosts our productivity significantly. Also, this feature encourages the developer to embrace re-usability when designing a piece of code.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=xN1d7bh9DeQ:x9NNdDC4Gj0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=xN1d7bh9DeQ:x9NNdDC4Gj0:G79ilh31hkQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?d=G79ilh31hkQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=xN1d7bh9DeQ:x9NNdDC4Gj0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=xN1d7bh9DeQ:x9NNdDC4Gj0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MrRoa?a=xN1d7bh9DeQ:x9NNdDC4Gj0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MrRoa?i=xN1d7bh9DeQ:x9NNdDC4Gj0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/MrRoa/~4/xN1d7bh9DeQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/MrRoa/~3/xN1d7bh9DeQ/7750176924</link><guid isPermaLink="false">http://mrroa.com/post/7750176924</guid><pubDate>Mon, 21 Sep 2009 00:00:00 -0400</pubDate><category>Visual Studio</category><category>Snippets</category><feedburner:origLink>http://mrroa.com/post/7750176924</feedburner:origLink></item></channel></rss>

