<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Abhijit&#039;s World of .NET &#187; ASP.NET</title>
	<atom:link href="http://abhijitjana.net/category/my-articles/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://abhijitjana.net</link>
	<description>Success is a journey , It’s not a destination</description>
	<lastBuildDate>Wed, 09 May 2012 17:50:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='abhijitjana.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/5686a1e614b4b192b9ff56ffbb1c9000?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Abhijit&#039;s World of .NET &#187; ASP.NET</title>
		<link>http://abhijitjana.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://abhijitjana.net/osd.xml" title="Abhijit&#039;s World of .NET" />
	<atom:link rel='hub' href='http://abhijitjana.net/?pushpress=hub'/>
		<item>
		<title>Dynamically set control visibility inside ItemTemplate&#8217;s of GridView using Bind Expression</title>
		<link>http://abhijitjana.net/2011/09/01/dynamically-set-control-visibility-inside-itemtemplates-of-gridview-using-bind-expression/</link>
		<comments>http://abhijitjana.net/2011/09/01/dynamically-set-control-visibility-inside-itemtemplates-of-gridview-using-bind-expression/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 12:46:34 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[BindingExpression]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[ItemTemplates]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=3031</guid>
		<description><![CDATA[GridView TemplateField allow us to specify custom controls, multiple fields and Html using a custom template. TemplateField allows us to define a completely customized template for GridView Column. We can bind the data with in template control using binding expression. ASP.NET provides number of ways to take control over the template control. In this post [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=3031&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>GridView <span style="color:#000080;">TemplateField</span> allow us to specify custom controls, multiple fields and Html using a custom template. <span style="color:#000080;">TemplateField</span> allows us to define a completely customized template for GridView Column. We can bind the data with in template control using binding expression. ASP.NET provides number of ways to take control over the template control. In this post I am going to discuss how we can set template control visibility based on certain condition which depends on the data source data. For example, imagine you have a link button within template field. You want to set visibility if that control based on the some value of your data source.</p>
<p><span id="more-3031"></span></p>
<p>Let’s consider we have below class for Customer entity. We will create a list of Customers and based on the value of “<span style="color:#000080;">ShowURL</span>” we are going to display the Web Sites URL.</p>
<p><pre class="brush: csharp;">

    /// &lt;summary&gt;
    /// Customer Class
    /// &lt;/summary&gt;
    internal sealed class Customer
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string WebSite { get; set; }
        public bool ShowURL { get; set; }
    }
</pre></p>
<p>Here’s the code snippet for creating List and binding with <span style="color:#000080;">GridView</span> Control.</p>
<p><pre class="brush: csharp;">
  /// &lt;summary&gt;
        /// Handles the Load event of the Page control.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;sender&quot;&gt;The source of the event.&lt;/param&gt;
        /// &lt;param name=&quot;e&quot;&gt;The &lt;see cref=&quot;System.EventArgs&quot;/&gt; instance containing the event data.&lt;/param&gt;
        protected void Page_Load(object sender, EventArgs e)
        {
            List&lt;Customer&gt; emps = new List&lt;Customer&gt;()
            {
                new Customer{ID=1, Name=&quot;Customer 1&quot;,WebSite=&quot;http://abhijitjana.net&quot;,ShowURL=true},
                new Customer{ID=2, Name=&quot;Customer 2&quot;,WebSite=&quot;http://abhisheksur.com&quot;,ShowURL=false},
                new Customer{ID=3, Name=&quot;Customer 3&quot;,WebSite=&quot;http://jebarson.info&quot; ,ShowURL=true},
                new Customer{ID=4, Name=&quot;Customer 4&quot;, WebSite=&quot;http://atulvarma.com&quot;, ShowURL=false}

                };
            myGrid.DataSource = emps;
            myGrid.DataBind();
        }
</pre></p>
<p>In this example we are going to illustrate the binding with <span style="color:#000080;">TemplateField</span>, so here is the design view of GridView where we have Two column with two different template field. First one is the container of Name and second on is the container of Web Site.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/09/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/09/image_thumb2.png?w=619&h=290" alt="image" width="619" height="290" border="0" /></a></p>
<p>Below images shows the output of the above binding.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/09/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/09/image_thumb3.png?w=466&h=212" alt="image" width="466" height="212" border="0" /></a></p>
<p>Well, as of now all the site link are getting displayed in the <span style="color:#000080;">GridView</span>. But we have to display the links based on the value of “<span style="color:#000080;">ShowURL</span>”  field.</p>
<p>The most common solution we can find is “set visibility during GridView <span style="color:#000080;">RowDataBound</span> Event” as shown in below</p>
<p><pre class="brush: csharp;">
/// &lt;summary&gt;
        /// Handles the RowDataBound event of the myGrid control.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;sender&quot;&gt;The source of the event.&lt;/param&gt;
        /// &lt;param name=&quot;e&quot;&gt;The &lt;see cref=&quot;System.Web.UI.WebControls.GridViewRowEventArgs&quot;/&gt; instance containing the event data.&lt;/param&gt;
        protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Customer cust = e.Row.DataItem as Customer;
                if (!cust.ShowURL)
                {
                    LinkButton lnkWebURL = e.Row.FindControl(&quot;lnk&quot;) as LinkButton;
                    if (lnkWebURL != null)
                    {
                        lnkWebURL.Visible = false;
                    }
                }
            }
        }
</pre></p>
<p>Above code will hide the link button from the GridView as shown in below image.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/09/image5.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/09/image_thumb5.png?w=425&h=211" alt="image" width="425" height="211" border="0" /></a></p>
<p>Well, do we really need to override <span style="color:#000080;">myGrid_RowDataBound()</span> for this small task ? Can’t we do it using Binding Expression. One similar question <a href="http://www.codeproject.com/Answers/246922/LinkButton-Inside-GridView-Visibility#answer2" target="_blank">had  asked over  at Code Project</a> and I am going to share the answer  which I have provided .</p>
<p>We can use Operator with in Bind Expression. Hence, we can set the visibility of Control using Binding Expression. We really don’t need to write code in <span style="color:#000080;">RowDataBound</span> just set the visibility of <span style="color:#000080;">LinkButton</span> as shown in below</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/09/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/09/image_thumb6.png?w=715&h=141" alt="image" width="715" height="141" border="0" /></a></p>
<p><em>How it works ?</em></p>
<p>This will do exactly we did in<span style="color:#000080;"> myGrid_RowDataBound()</span> event. But we followed a different approach.  <span style="color:#000080;">Eval(“ShowURL”)</span> find evaluate the value of ShowURL From the GridView data source and then set the properties of <span style="color:#000080;">LinkButton</span> <span style="color:#000080;">Visibility</span>.  Based on the visible properties of <span style="color:#000080;">LinkButton</span>, controls renders on page.</p>
<p>We can also use any conditional operator with in the  Binding Expression as well as shown in below</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/09/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/09/image_thumb7.png?w=534&h=88" alt="image" width="534" height="88" border="0" /></a></p>
<p>That’s all. Very simple, but this will give you some idea to think on using Binding Expression in different ways as well.</p>
<p>Hope this helps.</p>
<p>Cheers !</p>
<p>Aj</p>
<br />Filed under: <a href='http://abhijitjana.net/category/net-4-0/'>.NET 4.0</a>, <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/my-articles/c/'>C#</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/3031/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/3031/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/3031/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/3031/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/3031/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/3031/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/3031/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/3031/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=3031&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/09/01/dynamically-set-control-visibility-inside-itemtemplates-of-gridview-using-bind-expression/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/09/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/09/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/09/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/09/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/09/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Not able to view all the running Worker Process in Visual Studio &#8211; Process Attach Window &#8211; Resolution</title>
		<link>http://abhijitjana.net/2011/08/18/no-able-to-view-all-the-running-worker-process-in-visual-studio-process-attach-window-resolution/</link>
		<comments>http://abhijitjana.net/2011/08/18/no-able-to-view-all-the-running-worker-process-in-visual-studio-process-attach-window-resolution/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 14:35:25 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Beginners]]></category>
		<category><![CDATA[IIS 7.0]]></category>
		<category><![CDATA[Process Attach]]></category>
		<category><![CDATA[WorkerProcess]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/2011/08/18/no-able-to-view-all-the-running-worker-process-in-visual-studio-process-attach-window-resolution/</guid>
		<description><![CDATA[This might be a very simple and known to most of us, but I found  it as a query in a discussion forum of one of my article “Debug your ASP.NET Application while Hosted on IIS” which was published at Code Project . Question was regarding list of worker processes in “Process Attach window” of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2979&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This might be a very simple and known to most of us, but I found  it as a query in a <a href="http://www.codeproject.com/Messages/3869214/What-if-I-dont-have-w3wp-exe-running.aspx" target="_blank">discussion forum</a> of one of my article “<a href="http://www.codeproject.com/KB/aspnet/ProcessAttache.aspx" target="_blank">Debug your ASP.NET Application while Hosted on IIS</a>” which was published at <a href="http://www.codeproject.com" target="_blank">Code Project</a> . Question was regarding list of worker processes in “<span style="color:#000080;">Process Attach window</span>” of Visual studio. Though all the sites are running properly on IIS, still he was not able to view any processes in “<span style="color:#000080;">Attach Process Window</span>” while trying to attach a process from Visual Studio.</p>
<p><span id="more-2979"></span>Well the exact question was below,</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/08/image30.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/08/image_thumb30.png?w=732&h=40" alt="image" width="732" height="40" border="0" /></a></p>
<p>Visual Studio IDE Process Attach Window display below below information for processes</p>
<ul>
<li>Process Name</li>
<li>ID</li>
<li>Title</li>
<li>Type</li>
<li>User Name</li>
<li>Session</li>
</ul>
<p>In default view of Process Attach window, processes are filtered based on  <span style="color:#000080;">User Name</span>  which is current context user and the <span style="color:#000080;">Session</span>. So, if you are logged in with a user, let say &#8220;Domain\User1” and your Worker Process (w3wp.exe) is running on same account then only you can view the process over there. This is not only for the worker processes, it is true for all other processes as well.</p>
<p>So, if you worker process running on some other credentials ( Account on which your Application Pool Running ) , you won’t be able to see the worker process list .</p>
<p>To view all the process which are running one other credentials you have to select “<span style="color:#000080;">Show Process from all users</span>” and “<span style="color:#000080;">Show Processes in all sessions</span>” . On Select of the above two checkboxes you will able to view the all the running process from where you can select respective worker process (w3wp.exe) to attach.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/08/image31.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/08/image_thumb31.png?w=578&h=265" alt="image" width="578" height="265" border="0" /></a></p>
<p>Yes, pretty simple.  You can check out my answer here as well  <a title="http://bit.ly/nehkhH" href="http://bit.ly/nehkhH" target="_blank">http://bit.ly/nehkhH</a></p>
<blockquote><p>Here is one of my old post where I talked about <a href="http://abhijitjana.net/2010/07/15/identifying-worker-process-w3wp-exe-iis-6-0-and-iis-7-0-for-debugging-asp-net-application/">Identifying Worker Process (w3wp.exe) – IIS 6.0 and IIS 7.0 for Debugging ASP.NET Application</a> . This will help you to identify a particular worker process when multiple is running. If you are using IIS 7.0 and upper version you can take help of IIS Manager to identify the same.  This post will help you to know more details. <a href="http://abhijitjana.net/2010/11/04/how-to-use-iis-manager-to-get-worker-processes-w3wp-exe-details-information/">How to use IIS Manager to get Worker Processes (w3wp.exe) details information ?</a></p></blockquote>
<blockquote class='twitter-tweet'><p>[ New Blog Post ] Not able to view all the running Worker Process in Visual Studio &#8211; Process Attach Window &#8211; Resolution <a href="http://bit.ly/qgWZXa"> bit.ly/qgWZXa</a>&mdash; <br />Abhijit Jana (@AbhijitJana) <a href='http://twitter.com/#!/AbhijitJana/status/104202606028656643' data-datetime='2011-08-18T14:46:51+00:00'>August 18, 2011</a></p></blockquote>
<br />Filed under: <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/debugging/'>Debugging</a>, <a href='http://abhijitjana.net/category/iis/'>IIS</a>, <a href='http://abhijitjana.net/category/visual-studio/'>Visual Studio</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2979/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2979/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2979&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/08/18/no-able-to-view-all-the-running-worker-process-in-visual-studio-process-attach-window-resolution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/08/image_thumb30.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/08/image_thumb31.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Internals : Visualizing ASP.NET Page Life Cycle using IntelliTrace</title>
		<link>http://abhijitjana.net/2011/06/26/asp-net-internals-visualizing-asp-net-page-life-cycle-using-intellitrace/</link>
		<comments>http://abhijitjana.net/2011/06/26/asp-net-internals-visualizing-asp-net-page-life-cycle-using-intellitrace/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 22:53:25 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[IntelliTrace]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP.NET Internals]]></category>
		<category><![CDATA[page life cycle]]></category>
		<category><![CDATA[Visual Studio 2010 Ultimate]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2783</guid>
		<description><![CDATA[Understanding the ASP.NET Page Life Cycle is an essential knowledge for developing ASP.NET Web Application. When request come from client to server there are many operations performed in backend before sending response to the client. When client request for some information from a web server, request first reaches to HTTP.SYS, which is the kernel level [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2783&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Understanding the ASP.NET Page Life Cycle is an essential knowledge for developing ASP.NET Web Application. When request come from client to server there are many operations performed in backend before sending response to the client. When client request for some information from a web server, request first reaches to HTTP.SYS, which is the kernel level of IIS. HTTP.SYS then send the request to respective  Application Pool. Application Pool then forward the request to worker process to load the ISAPI Extension which will create an <span style="color:#646b86;">HTTPRuntime</span> Object to Process the request via <span style="color:#646b86;">HTTPModule</span> and <span style="color:#646b86;">HTTPHanlder</span>.  Once request passed through the HTPP Pipeline, ASP.NET Page Life Cycle Start.  You will find several articles that describes the What is ASP.NET Page lifecycle, what are the different events fired during page lifecycle.  This post is something different, I will show you how you can see the each and individual Page life cycle events using IntelliTrace</p>
<p><span id="more-2783"></span></p>
<p>If you wondering what is IntelliTrace,  Well, <a href="http://msdn.microsoft.com/en-us/library/dd264915.aspx">IntelliTrace</a> debugging  is only available with Visual Studio 2010 Ultimate edition, which collects debugging information in background and can be used at any point to time to analysis previous debugging data. IntelliTrace collected debugger information into a trace log file (.iTrace ) that can then be opened and debugged using Visual Studio later.  You can use the log file at any point of time to see what happened exactly at background during your live debugging. To know more details, you can see my several articles published on <a href="http://abhijitjana.net/?s=IntelliTrace">IntelliTrace</a>  and for step by step guide read “<a href="http://msdn.microsoft.com/en-us/magazine/ee336126.aspx">Debugging Application using IntelliTrace</a>” from MSDN .</p>
<p>As we are going to use IntelliTrace, first do the initial setup for IntelliTrace from <span style="color:#646b86;">Tools &gt; Option &gt; IntelliTrace</span>.  We have to select the second option “<span style="color:#646b86;">IntelliTrace events and call information</span>” as this setting will collects all the event as well as internal call information.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image37.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb33.png?w=476&h=279" alt="image" width="476" height="279" border="0" /></a></p>
<p>As of now, that is all about IntelliTrace setting, Let’s have a quick look into ASP.NET Page Life Cycle startup, Any request comes from clients, first hits the kernel level <span style="color:#646b86;">HTTP.SYS of IIS</span>.<span style="color:#646b86;">  HTTP.SYS and WAS Interacts</span> each others and pass the request to proper Application Pool. Then Worker Process takes care of each and individual request. If you are interested, please read one of my article,<a href="http://abhijitjana.net/2010/03/14/beginner%e2%80%99s-guide-how-iis-process-asp-net-request/"><span style="text-decoration:underline;">Beginner’s Guide: How IIS Process ASP.NET Request</span></a> which talks about internal of ASP.NET Request Processing. Once the request done with HTTP Pipeline Processing, request enters into Page Lifecycle  state.  Below pictures illustrate the same.</p>
<p>&nbsp;</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image48.png?w=660&h=248" alt="image" width="660" height="248" border="0" /></p>
<p>It is bit difficult to remember exactly what happens and when during the ASP.NET page lifecycle.  But if you really look into <a href="http://msdn.microsoft.com/en-us/library/ms178472.aspx#general_page_lifecycle_stages" target="_blank"><span style="text-decoration:underline;">general stages of ASP.NET Page lifecycle</span></a>, we can majorly classified below stages</p>
<ol>
<li>Page Request</li>
<li>Start</li>
<li>Page Initialization</li>
<li>Load</li>
<li>Validation</li>
<li>Postback event handling</li>
<li>Rendering</li>
<li>Unload</li>
</ol>
<p>To know more about each and individual stages, please read <a href="http://msdn.microsoft.com/en-us/library/ms178472.aspx" target="_blank"><span style="text-decoration:underline;">this article from MSDN</span></a> .</p>
<p>Now let me start with a simple web application that consist of a <em><span style="text-decoration:underline;">Master Pages, User Control and Main page</span></em> having some data in grid. I am putting master pages, user controls, grid view together  to show how they really works internally.  Both the Grid and User controls reads some data from Data Base.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image49.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb39.png?w=192&h=173" alt="image" width="192" height="173" border="0" /></a></p>
<p>If I run the web application, I will get the below out put.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image50.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb40.png?w=299&h=262" alt="image" width="299" height="262" border="0" /></a></p>
<p>Now, get back to Visual Studio and Break the IntelliTrace Event from IntelliTrace Window (<span style="color:#646b86;"> <strong>Debug &gt; Window &gt; IntelliTrace Call Window</strong></span> )</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image41.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb36.png?w=241&h=208" alt="image" width="241" height="208" border="0" /></a></p>
<p>Once you click on “<strong>Break All</strong>” , you will get so many events including thread, file access ( Which depends on IntelliTrace Settings ). But to make it very simple,<span style="text-decoration:underline;"> filter the information based on the ASP.NET</span> as shown in below picture</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image42.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb37.png?w=360&h=445" alt="image" width="360" height="445" border="0" /></a></p>
<p>Let’s have a in-depth look what are the information it captured.  If you click on the first event, which is actually an Asynchronous call the the HTTP Handler initialized and first GET request the ASPX Page.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image43.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb38.png?w=355&h=213" alt="image" width="355" height="213" border="0" /></a></p>
<p>Click on the “<strong>Call View”</strong> for more details, below information will appear which talks about many internal stuff of ASP.NET.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image44.png?w=644&h=367" alt="image" width="644" height="367" border="0" /></p>
<p>Let’s start with <span style="color:#646b86;">Application_Start()</span> Event is fired when the first instance of the <span style="color:#646b86;">HttpApplication</span> class is created. It allows you to create objects that are accessible by all <span style="color:#646b86;">HttpApplication</span> instances during the Application Life Cycle. If you click on the particular row in the IntelliTrace window, you will be automatically redirect to to code as well.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image51.png?w=633&h=229" alt="image" width="633" height="229" border="0" /></p>
<p>On finishing of the <span style="text-decoration:underline;">Application_Start(),</span> the next event fire is “<span style="text-decoration:underline;">Session_Start”.</span> IntelliTrace will also capture the information for Session.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image52.png?w=561&h=205" alt="image" width="561" height="205" border="0" /></p>
<p>Once the request passed through Session_Start(), it’s entered into actual Page Life Cycle state is which the Process Request for a particular page.  If you look at the below picture, it’s talks about  everything of a page life cycle.  IntelliTrace Captured all in-between events of  Page_Process Request Start to Page_Process Request End.  Note, we send the the request for <span style="text-decoration:underline;"><em>Defualt.aspx ( Get / Default.aspx)</em></span> , hence ASP.NET Engine will start the processing for Default.aspx.  As this Page has a user control and contain with in a Master page you can see there are several events fired with in process request that are related with master pages and user controls.  <img style="background-image:none;padding-left:0;padding-right:0;display:inline;float:left;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image47.png?w=692&h=431" alt="image" width="692" height="431" align="left" border="0" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><em> Image : Page Process Request </em></p>
<p>Before explaining about the above images, here is some golden rule that ASP.NET follows during page life cycle events.  <span style="color:#4f81bd;">PreInit()</span> of request pages fired first and followed by <span style="color:#000000;"><span style="text-decoration:underline;">init event of User Control</span></span>, <span style="text-decoration:underline;">Master Pages</span> and then <span style="text-decoration:underline;">finally init event for the requested page</span>. This is the sequence how ASP.NET fired up events. Below image illustrate the same.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image53.png?w=409&h=274" alt="image" width="409" height="274" border="0" /></p>
<p>Now, coming back to Page Process Request image, I have marked the images with few numbers to under stand the sequence of execution.</p>
<p>With the start of ASP.NET Page Process Request, ASP.NET runtime engine called a method ASP.&lt;Pagename&gt; _aspx.FrameworkInitialize() , or <a href="http://msdn.microsoft.com/en-us/library/56h09azw%28v=vs.90%29.aspx" target="_blank">Page.FrameworkInitialize()</a> method  to initializes the Page object and creates the control tree based on the declarative nature of the page. One more thumb rule here is, you should not override this methods, if you are doing so don’t forget to call base class&#8217;s FrameworkInitialize method.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image54.png?w=416&h=333" alt="image" width="416" height="333" border="0" /></p>
<p>If you again deep dive with with in Bind Control Tree,  you can see the each and every control binding.  During this phase asp.net did some top level binding for aspx pages, like page title set, setting up the master pages and also Add the Content Templates for Content Place holder. Note, if you don’t have the master page, you won’t be able to see this events during page life cycle. I took example with master page so that I can cover all the stuff.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image55.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb41.png?w=651&h=381" alt="image" width="651" height="381" border="0" /></a></p>
<p>&nbsp;</p>
<p>Once done with the FrameworkInitialize(), Request moves to <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.preinit.aspx" target="_blank">Page OnPreInit()</a> events.  If you use the IntelliTrace navigator, you can go to inside of event recorded by IntelliTrace also can see the corresponding code.   You can read <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.preinit.aspx" target="_blank">Page.PreInit()</a> for more details.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image56.png?w=583&h=263" alt="image" width="583" height="263" border="0" /></p>
<p>&nbsp;</p>
<p>Once done with PreInit(),  request moves to FrameworkInitilization() of Master Page. During this phase, ASP.NET creates control tree for the master pages.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image57.png?w=727&h=255" alt="image" width="727" height="255" border="0" /></p>
<p>during this phase you can also find , how each and every controls adding to control tree.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image58.png?w=541&h=269" alt="image" width="541" height="269" border="0" /></p>
<p>&nbsp;</p>
<p>Once ASP.NET done with FrameworkInitialize of  Master pages,  ASP.NET engine fires Init() event for  User Control . This events raised after all controls have been initialized . <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.init.aspx" target="_blank">Read more about Init()</a></p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image59.png?w=619&h=163" alt="image" width="619" height="163" border="0" /></p>
<p>The next event it will fire is, init of Master page, if you are not overriding it the event will move to Init() event  of Default.aspx page.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image60.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb42.png?w=463&h=268" alt="image" width="463" height="268" border="0" /></a></p>
<p>Once done with Page_Init(), ASP.NET fires Page_Load() event for  default.aspx page. followed by Page_Load of Mater Page and then User Control . Below is the sequence diagram for Page_Load() for page, master page and User control, yes it’s revers the over of Init() method.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image61.png?w=321&h=193" alt="image" width="321" height="193" border="0" /></p>
<p>IntelliTrace Traps the Same, Using IntelliTrace we can see, first Page_Load() of default.aspx fires, followed by Page_Load() of master page, then Page_Load() of User control.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image62.png?w=669&h=357" alt="image" width="669" height="357" border="0" /></p>
<p>In the next phase, before Saving the Data on View State it will load all the data from backend . You can see the corresponding ADO.NET events, that fires for load data from from backend saver.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image63.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb43.png?w=535&h=160" alt="image" width="535" height="160" border="0" /></a></p>
<p>Once that is done, SaveViewState() methods is been called to store the data with in View State.  “<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.savestatecomplete.aspx" target="_blank">Save State Completed”</a> raised after view state and control state have been saved for the page and for all controls.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image64.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;margin-left:0;margin-right:0;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb44.png?w=589&h=131" alt="image" width="589" height="131" border="0" /></a></p>
<p>once the View data been saved, ASP.NET calls <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.render.aspx" target="_blank">Render</a> method that that writes out the control&#8217;s markup to send to the browser</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image65.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;margin-left:0;margin-right:0;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb45.png?w=714&h=111" alt="image" width="714" height="111" border="0" /></a></p>
<p>You can also override other methods of page lifecycle to get more details view. On Page Post back, you can explore the different events for post back as well,  like if you clicked on some button, IntelliTrace will show you how post back has been initialized also you can view the sequence of ASP.NET Page life while post back.</p>
<p>To summarize the whole stuff, I have discussed how you can use the power of IntelliTrace to visualize the each and every events which are related with ASP.NET Page life cycle. Most of us knows about the basic events of Page Life Cycle, but using IntelliTrace you must have see something new stuff and also  seen what are the internal methods been called during page lifecycle.</p>
<p>That’s all guys !  Hope you have enjoyed the reading ! Let me know if you have any query regarding this !</p>
<p>Cheers !</p>
<p>Aj</p>
<blockquote class='twitter-tweet'><p>ASP.NET Internals : Visualizing ASP.NET Page Life Cycle using IntelliTrace <a href="http://wp.me/ppvPE-IT" rel="nofollow">http://wp.me/ppvPE-IT</a>&mdash; <br />Abhijit Jana (@AbhijitJana) <a href='http://twitter.com/#!/AbhijitJana/status/84929421777190912' data-datetime='2011-06-26T10:22:06+00:00'>June 26, 2011</a></p></blockquote>
<br />Filed under: <a href='http://abhijitjana.net/category/net-4-0/'>.NET 4.0</a>, <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/asp-net-4-0/'>ASP.NET 4.0</a>, <a href='http://abhijitjana.net/category/intellitrace/'>IntelliTrace</a>, <a href='http://abhijitjana.net/category/visual-studio/'>Visual Studio</a>, <a href='http://abhijitjana.net/category/visual-studio-2010/'>Visual Studio 2010</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2783/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2783&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/06/26/asp-net-internals-visualizing-asp-net-page-life-cycle-using-intellitrace/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb33.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image48.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb39.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb40.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb36.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb37.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb38.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image44.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image51.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image52.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image47.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image53.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image54.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb41.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image56.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image57.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image58.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image59.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb42.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image61.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image62.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb43.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb44.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb45.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Internals : &#8220;Clearing ASP.NET Session Variables&#8221; a in-depth look</title>
		<link>http://abhijitjana.net/2011/06/04/asp-net-internals-clearing-asp-net-session-variables-a-in-depth-look/</link>
		<comments>http://abhijitjana.net/2011/06/04/asp-net-internals-clearing-asp-net-session-variables-a-in-depth-look/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 21:04:05 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP.NET Internals]]></category>
		<category><![CDATA[Difference between Session.Clear Vs Session.RemoveAll]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[Session.Clear Vs Session.RemoveAll]]></category>
		<category><![CDATA[state Management]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/2011/06/04/asp-net-internals-clearing-asp-net-session-variables-a-in-depth-look/</guid>
		<description><![CDATA[ASP.NET Session is one of most common state management technique for any ASP.NET Web Application.  If you want to do a quick refresh or want to know some thing more, please go ahead and read one of my article “Exploring Session in ASP.NET” published at Code Project.  ASP.NET provides several methods for removing Session. But [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2667&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ASP.NET Session is one of most common state management technique for any ASP.NET Web Application.  If you want to do a quick refresh or want to know some thing more, please go ahead and read one of my article “<a href="http://www.codeproject.com/KB/aspnet/ExploringSession.aspx">Exploring Session in ASP.NET</a>” published at Code Project.  ASP.NET provides several methods for removing Session. But which methods needs to use at what time, is a must known stuff for asp.net developer. In this post I going to talk about bit internals of removing session variables from applications. Why this Post ?  I found many people having some confusion around removing / clearing the  session variable ( Mainly with Session.Clear(), Session.RemoveAll(), Session.Abandon()) , which method needs to use, what is the purpose of particular method etc.</p>
<p><span id="more-2667"></span></p>
<p>ASP.NET Provides below methods to clearing or removing Session information.</p>
<ul>
<li>Session.Clear()</li>
<li>Session.RemoveAll()</li>
<li>Session.Abandon()</li>
<li>Session.RemoveAt(index)</li>
<li>Session.Remove(string);</li>
</ul>
<p>We will be mainly focusing the first 3 methods.</p>
<p>Let’s start with <em>Session.Clear()</em> and <em>Session.RemoveAll().</em> Well, you may ask, why I am starting with two methods together. Yes, we are in same track. Both <em>Session.Clear()</em> and <em>Session.RemoveAll() </em>does the same job. Let’s explore it</p>
<p><span style="color:#646b86;"><span style="text-decoration:underline;"><strong>Session.Clear () Vs. Session.RemoveAll()</strong> </span></span></p>
<p>Let’s assume  stored below information with in session variable.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image.png?w=375&h=115" alt="image" width="375" height="115" border="0" /></p>
<p>now, if you want to remove all the items from session you can use either <em>Session.RemoveAll()</em> or <em>Session.Clear().</em>   if you check the definition  from meta data file you will get below details, where description says the same.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image1.png?w=548&h=186" alt="image" width="548" height="186" border="0" /></p>
<p>Then what is the difference between these two ? Ok, <span style="text-decoration:underline;"><em>Session.RemoveAll() Calls Clear() method internally</em></span>. Yes it is.  if you explore this with <a href="http://msdn.microsoft.com/en-us/library/f7dy01k1%28VS.80%29.aspx">IL Disassembler</a> ( for <span style="color:#000040;">Session.Web.dll</span> ) you will find, Session.RemoveAll() is calling Clear() for that the session object instance.</p>
<p>Open<a href="http://msdn.microsoft.com/en-us/library/f7dy01k1%28VS.80%29.aspx"> IL DASM</a>, browse System.Web.dll from Framework Directory and navigate to <span style="text-decoration:underline;"><span style="color:#000040;">System.web &gt; System.Web.SessionState &gt; System.Web.SessionState.HttpSessionState</span></span></p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb.png?w=427&h=466" alt="image" width="427" height="466" border="0" /></a></p>
<p>Now check for <span style="text-decoration:underline;">Clear() and RemoveAll()</span> method using IL DASM</p>
<p><strong>Session.Clear() : </strong></p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb1.png?w=632&h=167" alt="image" width="632" height="167" border="0" /></a></p>
<p><strong>Session.RemoveAll() : Calling Clear() internally.</strong></p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image4.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb2.png?w=637&h=160" alt="image" width="637" height="160" border="0" /></a></p>
<p>If this looks like bit difficult to understand you can use Reflector ( <a href="http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1" target="_blank">I used Red get Reflector, you can download free trial)</a>  to get the more details.</p>
<p>As show in below image, Session.Clear()  clearing the Session Container .</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image5.png?w=647&h=324" alt="image" width="647" height="324" border="0" /></p>
<p>And if you check the details for Session.RemoveAll(), you will find, it is calling Clear() method internally.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb3.png?w=641&h=317" alt="image" width="641" height="317" border="0" /></a></p>
<p>Most important thing, you can check the dependency graph for this two method, you will find, Session.RemoveAll() depends on Clear() method.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb4.png?w=639&h=240" alt="image" width="639" height="240" border="0" /></a></p>
<p>Session.Clear() is used by RemoveAll() and Session.RemoveAll() depends on Session.Clear() <img class="wlEmoticon wlEmoticon-thumbsup" style="border-style:none;" src="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-thumbsup.png?w=460" alt="Thumbs up" /></p>
<p>Now, what does this two methods do ?</p>
<ul>
<li>They  removes all keys and values from the session-state collection . which means just remove the session items nothing more than that and session ID Will remain Same</li>
</ul>
<p>Session ID Before Remove</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/06/image8.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image_thumb5.png?w=608&h=170" alt="image" width="608" height="170" border="0" /></a></p>
<p>Now, if you use Session.RemoveAll() or Session.Clear() , it will just clear the items from session collection, but Session Id will remain Same.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/06/image9.png?w=609&h=251" alt="image" width="609" height="251" border="0" /></p>
<p>This means, if you add another new  element in the same session context, ID will remain same.</p>
<p>Now, you may have once question, why we need two different method where as they are performing the same job. Well as per my understand this is just for providing a generic using of collection by using RemoveAll() method and supporting the all other previous method structure. Clear() is their from beginning from Classic ASP Version, which used to do the clean up the Session Container. So RemoveAll() is just a wrapper which use Clear() internally and provide a collection method to remove all the session information.</p>
<blockquote><p><img class="wlEmoticon wlEmoticon-pointingup" style="border-style:none;" src="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-pointingup.png?w=460" alt="Pointing up" /> Session.Clear() and Session.RemoveAll() never raised Session_End() . Session_End raised by Session.abandon() and if we are not explicitly calling the Abandon(), then Session_End will fire on SessionTimeOut</p></blockquote>
<p>Hope this give you a clear understanding of internal details of Session.RemoveAll() and Session.Clear().</p>
<p>where as <a href="http://msdn.microsoft.com/en-us/library/ms524310%28VS.90%29.aspx">Abandon</a> method destroys all the objects stored in a <a href="http://msdn.microsoft.com/en-us/library/ms524319%28VS.90%29.aspx">Session</a> object and releases their resources. Once you call this method, Session_End will raised automatically.</p>
<blockquote><p><img class="wlEmoticon wlEmoticon-highfive" style="border-style:none;" src="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-highfive.png?w=460" alt="High five" /> When you abandon a session, the session ID cookie is not removed from the browser of the user. Therefore, as soon as the session has been abandoned, any new requests to the same application will use the same session ID but will have a new session state instance.</p>
<p><span style="font-size:x-small;">Read Complete Details on : <a href="http://support.microsoft.com/?kbid=899918" target="_blank">How and why session IDs are reused in ASP.NET</a></span></p></blockquote>
<p>If we don’t call <a href="http://msdn.microsoft.com/en-us/library/ms524310%28VS.90%29.aspx">Abandon</a> method explicitly, the server destroys these objects when the session times out.  Which means, for Session.Clear() and Session.RemoveAll(), just session data get removed, but session still alive, but Session.Abandon() Destroy the all object.</p>
<p>So, if you want to know the main difference with Session.Clear() / Session.RemoveAll()  and Session.Abandon()</p>
<ul>
<li>Clear removes items immediately from session collection, Abandon destroy the objects.</li>
<li>Abandon raised Session.End()</li>
<li>Clear keeps SessionState and resources associated with it where as abandon releases them and GC can collect them any time</li>
</ul>
<p><img class="wlEmoticon wlEmoticon-messenger" style="border-style:none;" src="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-messenger.png?w=460" alt="Messenger" /> Here is an nice link, which talk about different opinion about this three methods <a title="http://bit.ly/kr7diK" href="http://bit.ly/kr7diK">http://bit.ly/kr7diK</a></p>
<p>And, finally <em>Session.RemoveAt(index)</em> and <em>Session.Remove(string)</em> removed the item from specified index and from given item name of session collection. If either of index or item variable missing, it will throw an exception. This methods are useful when we want to remove some specific item from session Collection.</p>
<p>Well, that’s all. The main objective was to look inside Session.Clear(), Session.RemoveAll() and Session.Abandon(). Hope this gave you a good understanding.</p>
<p>Cheers !</p>
<p>Abhijit</p>
<blockquote class='twitter-tweet'><p>[New Blog Post ] ASP.NET Internals : &quot;Clearing ASP.NET Session Variables&quot; a in-depth look <a href="http://wp.me/ppvPE-H1" rel="nofollow">http://wp.me/ppvPE-H1</a> <a href="http://twitter.com/search?q=%23aspnet" title="#aspnet">#aspnet</a> <a href="http://twitter.com/search?q=%23dotnet" title="#dotnet">#dotnet</a> <a href="http://twitter.com/search?q=%23webdev" title="#webdev">#webdev</a> <a href="http://twitter.com/search?q=%23dev" title="#dev">#dev</a>&mdash; <br />Abhijit Jana (@AbhijitJana) <a href='http://twitter.com/#!/AbhijitJana/status/76756735066505218' data-datetime='2011-06-03T21:06:46+00:00'>June 03, 2011</a></p></blockquote>
<br />Filed under: <a href='http://abhijitjana.net/category/net-4-0/'>.NET 4.0</a>, <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2667/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2667&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/06/04/asp-net-internals-clearing-asp-net-session-variables-a-in-depth-look/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-thumbsup.png" medium="image">
			<media:title type="html">Thumbs up</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/image9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-pointingup.png" medium="image">
			<media:title type="html">Pointing up</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-highfive.png" medium="image">
			<media:title type="html">High five</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/06/wlemoticon-messenger.png" medium="image">
			<media:title type="html">Messenger</media:title>
		</media:content>
	</item>
		<item>
		<title>Generic Way to Bind Enum With Different ASP.NET List Controls</title>
		<link>http://abhijitjana.net/2011/04/04/generic-way-to-bind-enum-with-different-asp-net-list-controls/</link>
		<comments>http://abhijitjana.net/2011/04/04/generic-way-to-bind-enum-with-different-asp-net-list-controls/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 18:34:33 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Bind]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[ListControls]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2510</guid>
		<description><![CDATA[In this post I am going to explain how we can bind a Enum with ASP.NET List Controls. These comprise of four different types of control, CheckBoxList, DropDownList, ListBox and RadioButtonList. This is one of the common requirements during development to bind a Enum with List Control and challenge is when we need to bind [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2510&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I am going to explain how we can bind a Enum with ASP.NET List Controls. These comprise of four different types of control, <span style="color:#000080;">CheckBoxList</span>, <span style="color:#000000;">DropDownList</span>, ListBox and RadioButtonList. This is one of the common requirements during development to bind a Enum with List Control and challenge is when we need to bind the both text and value.<br />
Let’s consider we have the blow Enum. Now I am going to bind it with all the above mentioned type List Controls.<br />
<a href="http://abhijitjana.files.wordpress.com/2011/04/image.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb.png?w=240&h=193" alt="image" width="240" height="193" /></a></p>
<p>Well, One of the easiest way that we can implement is by <a href="http://msdn.microsoft.com/en-us/library/system.enum.getnames.aspx">Enum.GetNames(Type enumType)</a>which retrieves the name list of enumberation  and <a href="http://msdn.microsoft.com/en-us/library/system.enum.getnames.aspx">Enum.GetValues(Type enumType)</a>, which returns the list of values for each names .<br />
<span id="more-2510"></span></p>
<p>Once we have the Names and Values, we can easily bind with any ListControl by just iterating with them.</p>
<p><pre class="brush: csharp;">
  public void BindEnumToListControls(Type enumType, ListControl listcontrol)
        {
            string[] names;
            Array values;
            int countElements, upperBound, lowerBound;
            names = Enum.GetNames(enumType);
            values = Enum.GetValues(enumType);
            for (countElements = 0; countElements &lt;= names.Length - 1; countElements++)
            {
                listcontrol.Items.Add(new ListItem(names[countElements].ToString(), values.GetValue(countElements).ToString()));
            }
        }
</pre></p>
<p>You will have the below output</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/04/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb2.png?w=449&h=315" border="0" alt="image" width="449" height="315" /></a></p>
<p>Now let’s have a quick look on how to call BindEnumToListControls() method, yeah very simple</p>
<p><pre class="brush: csharp;">
  protected void Page_Load(object sender, EventArgs e)
        {
            BindEnumToListControls(typeof(CustomerType), DropDownList1);
            BindEnumToListControls(typeof(CustomerType), checkboxlist);
            BindEnumToListControls(typeof(CustomerType), ListBox1);
            BindEnumToListControls(typeof(CustomerType), RadioButtonList1);
        }
</pre></p>
<blockquote><p><a href="http://abhijitjana.files.wordpress.com/2011/04/image4.png"><img style="display:inline;float:left;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb4.png?w=115&h=87" alt="image" width="115" height="87" align="left" /></a> You must be thinking why iterating through each and every names why not using LINQ instead of that.  Well, it’s time to optimized it . <img class="wlEmoticon wlEmoticon-hotsmile" style="border-style:none;" src="http://abhijitjana.files.wordpress.com/2011/04/wlemoticon-hotsmile.png?w=460" alt="Hot smile" /></p></blockquote>
<p>The easiest way to do it with LINQ is to convert the enum into Dictionary and Set the DataSource of List. Why Dictionary ? Because we want to bind with both Key and Value Pair for Dropdown list.</p>
<p><pre class="brush: csharp;">
  public void BindEnumToListControls(Type enumType, ListControl listcontrol)
        {
            string [] names = Enum.GetNames(enumType);
           List.DataSource = strNames.Select((key, value) =&gt;
                                       new { key, value }).ToDictionary(x =&gt; x.key, x =&gt; x.value + 1);
            listcontrol.DataTextField = &quot;Key&quot;;
            listcontrol.DataValueField = &quot;Value&quot;;
            listcontrol.DataBind();
        }
</pre></p>
<p>Above code will do the same as we have in the previous output.  But this approach certainly having a small problem . <img class="wlEmoticon wlEmoticon-donttellanyonesmile" style="border-style:none;" src="http://abhijitjana.files.wordpress.com/2011/04/wlemoticon-donttellanyonesmile.png?w=460" alt="Don't tell anyone smile" /> . If you look into the ViewSource of the above generated html and verify the Value Field for each and every control. All the value field are containing the sequential value.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/04/image6.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb6.png?w=616&h=401" alt="image" width="616" height="401" /></a></p>
<p>In some certain case, Enum may contain the Value as well, so that time we need to bind the actual value instead of overriding the value while creating the Dictionary as shown in below snippet .</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/04/image7.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb7.png?w=432&h=63" alt="image" width="432" height="63" /></a></p>
<p>I was thinking for some different approach but which leads me using for-each only. Then I look for some solution, and found one <a href="http://byatool.com/utilities/another-silly-method-just-for-you/">very interesting post,</a> which handles this in a smart way.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/04/image8.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb8.png?w=556&h=144" border="0" alt="image" width="556" height="144" /></a></p>
<p><pre class="brush: csharp;">
      public void BindEnumToListControls(Type enumType, ListControl listcontrol)
        {
            string [] names = Enum.GetNames(enumType);
            listcontrol.DataSource = Enum.GetValues(typeof(CustomerType)).Cast&lt;Int32&gt;()
                                      .ToDictionary(currentItem =&gt;
                                          Enum.GetName(typeof(CustomerType), currentItem));
            listcontrol.DataTextField = &quot;Key&quot;;
            listcontrol.DataValueField = &quot;Value&quot;;
            listcontrol.DataBind();
        }
</pre></p>
<p>Now from the below image, you can see the Customer Type value is applied to the List elements.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/04/image9.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/04/image_thumb9.png?w=562&h=279" alt="image" width="562" height="279" /></a></p>
<blockquote><p>Looking for simplest and handy  ways, here is two nice post by <a title="Suprotim Agarwal" href="http://twitter.com/SuprotimAgarwal" target="_blank">Suprotim Agarwal </a></p>
<p><a href="http://www.devcurry.com/2009/04/how-to-bind-aspnet-dropdownlist-to.html">How to Bind an ASP.NET DropDownList to an Enumeration with two lines of code</a></p>
<p><a href="http://www.devcurry.com/2009/09/how-to-bind-enum-name-and-value-to.html">How to Bind An Enum Name and Value to an ASP.NET DropDownList</a></p></blockquote>
<p>Cheers !<br />
AJ</p>
<br />Filed under: <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/asp-net-4-0/'>ASP.NET 4.0</a>, <a href='http://abhijitjana.net/category/tips-and-tricks/'>Tips and Tricks</a>, <a href='http://abhijitjana.net/category/visual-studio/'>Visual Studio</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2510/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2510&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/04/04/generic-way-to-bind-enum-with-different-asp-net-list-controls/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/wlemoticon-hotsmile.png" medium="image">
			<media:title type="html">Hot smile</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/wlemoticon-donttellanyonesmile.png" medium="image">
			<media:title type="html">Don&#039;t tell anyone smile</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/04/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a simple Context Sensitive Help for ASP.NET Controls using jQuery</title>
		<link>http://abhijitjana.net/2011/03/15/creating-a-simple-context-sensitive-help-for-asp-net-controls-using-jquery/</link>
		<comments>http://abhijitjana.net/2011/03/15/creating-a-simple-context-sensitive-help-for-asp-net-controls-using-jquery/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 16:36:20 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[jQuery Context Sensitive Help]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2436</guid>
		<description><![CDATA[In this blog post I am going to explain how we can create a simple  Context Sensitive Help for ASP.NET Controls using jQuery. This has been done based on the selection of a controls in a ASP.NET Web Form. On control selection / focus  jQuery Loads a  HTML Content from a remote file, then it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2436&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this blog post I am going to explain how we can create a simple  <span style="color:#000080;"><a class="zem_slink" title="Context-sensitive help" rel="wikipedia" href="http://en.wikipedia.org/wiki/Context-sensitive_help">Context Sensitive Help</a></span> for <span style="color:#000080;">ASP.NET Controls</span> using <span style="color:#000080;"><a class="zem_slink" title="JQuery" rel="homepage" href="http://jquery.com/">jQuery</a></span>. This has been done based on the <span class="zem_slink">selection</span> of a controls in a ASP.NET Web Form. On control selection / focus  jQuery Loads a  <a class="zem_slink" title="HTML" rel="wikipedia" href="http://en.wikipedia.org/wiki/HTML">HTML</a> Content from a remote file, then it&#8217;s apply the filter based on the control id and inject the filtered content into a predefined placeholder  with in the <a class="zem_slink" title="Document Object Model" rel="wikipedia" href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a> Hierarchy.</p>
<p><span id="more-2436"></span></p>
<p>To make it very simple let’s consider we have a <span class="zem_slink">contact form</span> with Name, Email, <span class="zem_slink">Web Site</span> and Comments Field. Our objective is to load and show the help content based on the control selection as shown in below image.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image21.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb21.png?w=507&h=245" alt="image" width="507" height="245" /></a></p>
<p>Content for the help file is being retrieved from one static <span style="color:#000080;">HTML </span>file which is kept in the server. On the selection of the ASP.NET control, based on the <span style="color:#000080;">Control Id</span> we have to retrieved the content.</p>
<p>Below is the HTML Content which is being read as help content for the controls.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image22.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb22.png?w=491&h=187" border="0" alt="image" width="491" height="187" /></a></p>
<p>One selection of  any <a class="zem_slink" title="Text box" rel="wikipedia" href="http://en.wikipedia.org/wiki/Text_box">Text Box</a> in web form, <span style="color:#000080;">jQuery </span>will send a call to sever to load the Help content for Text box. Now question is how the content is getting matched with the control ? . This is simply done using <span style="color:#000080;">Control Id</span>. You may have noticed that I have given an  id for every  <a class="zem_slink" title="Span and div" rel="wikipedia" href="http://en.wikipedia.org/wiki/Span_and_div">div element</a> which is actually the same id of the ASP.NET Control in our web forms. On  every jQuery.Load() after loading the file form server, first filter will apply then content will be rendered.</p>
<p>Below is the sample code for the same</p>
<p><pre class="brush: jscript;">
 &lt;script type=&quot;text/javascript&quot;&gt;
        $(document).ready(function () {
            var textboxes = $(&quot;:text&quot;);
            var textareas = $(&quot;textarea&quot;);
            $(&quot;:text&quot;).focus(function () {
                textboxes.removeClass(&quot;textboxstyleClass&quot;);
                textareas.removeClass(&quot;textboxstyleClass&quot;);
                $(this).addClass(&quot;textboxstyleClass&quot;);
                var id = $(this).attr('id');
                $(&quot;#helpviewer&quot;).slideUp();
                $(&quot;#helpviewer&quot;).slideDown(&quot;slow&quot;);
                $(&quot;#helpviewer&quot;).load('Help/Help.htm ' + &quot;#&quot; + id);
            });

            $(&quot;textarea&quot;).focus(function () {
                textboxes.removeClass(&quot;textboxstyleClass&quot;);
                $(this).addClass(&quot;textboxstyleClass&quot;);
                var id = $(this).attr('id');
                $(&quot;#helpviewer&quot;).slideUp();
                $(&quot;#helpviewer&quot;).slideDown(&quot;slow&quot;);
                $(&quot;#helpviewer&quot;).load('Help/Help.htm ' + &quot;#&quot; + id);
            });
        });
    &lt;/script&gt;

</pre></p>
<p><strong>How it works ?</strong></p>
<p>Let’s have a quick look how the things happens in back end. Below diagram is the over all representation of the whole process.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image23.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb23.png?w=631&h=415" border="0" alt="image" width="631" height="415" /></a></p>
<p>Let me explain the steps by considering  “<span style="color:#000080;">Email</span>” text box has been selected by end user</p>
<p><span style="color:#000080;">1.</span> On Selection of “<span style="color:#000080;">Email</span>” Text Box,  <span style="color:#000080;">Control.focus()</span> event will fire, as this has already been associated with the text box.</p>
<p><span style="color:#000080;">2.</span> Below statement gets the “id” for corresponding selected textbox control.</p>
<p><pre class="brush: jscript;">
var id = $(this).attr('id');
</pre></p>
<p><span style="color:#000080;">3. </span> Now Current Value of<span style="color:#000080;"> id=”textEmail”</span> [ As we considered “<span style="color:#000080;">Email</span>” text box is selected ]</p>
<p><span style="color:#000080;">4. $(control).load()</span> will actually do the job for reading the content from server. <a href="http://api.jquery.com/load/" target="_blank">Please read more about .load() function</a></p>
<p>below code block will load all the content and render the value with  &#8220;helpviewer&#8221; placeholder.</p>
<p><pre class="brush: jscript;">
$(&quot;#helpviewer&quot;).load('Help/Help.htm ')
</pre></p>
<p>But, as we need the filtered content, we need to pass the ID of the control to  filtered the content based on the id.</p>
<p>On run time, below is the constructed statement which is been used to load the<span style="color:#000080;"> Help Text  content for Email Text Box</span>.</p>
<p><pre class="brush: jscript;">
$(&quot;#helpviewer&quot;).load('Help/Help.htm #textEmail ')
</pre></p>
<p><span style="color:#000080;">5/ 6 / 7</span> . Content filtered based on the id and rendered with the div element.</p>
<p>I have added few animated event like <span style="color:#000080;">showup()</span> and <span style="color:#000080;">showdown() </span>to looks the things bit fancy.</p>
<p><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image24.png?w=333&h=49" alt="image" width="333" height="49" /></p>
<h2><span style="color:#000080;">Quick Demo</span><br />
<embed src="http://blip.tv/play/AYKrun4C" type="application/x-shockwave-flash" width="480" height="300" allowscriptaccess="never" allowfullscreen="true"></embed></h2>
<p>Below is the complete code block .</p>
<p><pre class="brush: jscript;">
 &lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Contacts.aspx.cs&quot; Inherits=&quot;Contacts&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;style type=&quot;text/css&quot;&gt;
        td
        {
            font-weight: 100;
            color: brown;
        }
        table
        {
            border: 1px solid gray;
        }

        .textboxClass
        {
            border: 1px;
            border-color: #6E6E6E;
            border-style: solid;
            background-color: #ffffff;
        }

        .textboxstyleClass
        {
            border: 1px;
            border-color: #C73E2C;
            border-style: solid;
            background-color: #D9D9D9;
        }

        #btnsubmit
        {
            border: 1px;
            border-color: #C73E2C;
            border-style: solid;
            background-color: #D9D9D9;
        }
    &lt;/style&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;Scripts/jquery-1.4.1.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        $(document).ready(function () {
            var textboxes = $(&quot;:text&quot;);
            var textareas = $(&quot;textarea&quot;);
            $(&quot;:text&quot;).focus(function () {
                textboxes.removeClass(&quot;textboxstyleClass&quot;);
                textareas.removeClass(&quot;textboxstyleClass&quot;);
                $(this).addClass(&quot;textboxstyleClass&quot;);
                var id = $(this).attr('id');
                $(&quot;#helpviewer&quot;).slideUp();
                $(&quot;#helpviewer&quot;).slideDown(&quot;slow&quot;);
                $(&quot;#helpviewer&quot;).load('Help/Help.htm ' + &quot;#&quot; + id);
            });

            $(&quot;textarea&quot;).focus(function () {
                textboxes.removeClass(&quot;textboxstyleClass&quot;);
                $(this).addClass(&quot;textboxstyleClass&quot;);
                var id = $(this).attr('id');
                $(&quot;#helpviewer&quot;).slideUp();
                $(&quot;#helpviewer&quot;).slideDown(&quot;slow&quot;);
                $(&quot;#helpviewer&quot;).load('Help/Help.htm ' + &quot;#&quot; + id);
            });
        });
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt;table cellpadding=&quot;2&quot; cellspacing=&quot;2&quot;&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot;&gt;
                    &lt;div style=&quot;border-bottom-style: 1px;&quot;&gt;
                        Contact Form
                    &lt;/div&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    Name
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:TextBox CssClass=&quot;textboxClass&quot; runat=&quot;server&quot; ID=&quot;textName&quot; Width=&quot;348px&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    Email
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:TextBox CssClass=&quot;textboxClass&quot; runat=&quot;server&quot; ID=&quot;textEmail&quot; Width=&quot;348px&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    Web Site
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:TextBox CssClass=&quot;textboxClass&quot; runat=&quot;server&quot; ID=&quot;textWebSite&quot; Width=&quot;348px&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    Comments
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:TextBox CssClass=&quot;textboxClass&quot; runat=&quot;server&quot; TextMode=&quot;MultiLine&quot; ID=&quot;textComments&quot;
                        Height=&quot;72px&quot; Width=&quot;425px&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot; align=&quot;right&quot;&gt;
                    &lt;asp:Button ID=&quot;btnsubmit&quot; Text=&quot;Submit&quot; runat=&quot;server&quot; /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=&quot;2&quot;&gt;
                    &lt;div id=&quot;helpviewer&quot; style=&quot;border: 1px solid gray; display: none&quot;&gt;
                    &lt;/div&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

</pre></p>
<p>This is a simple demonstration, you can use this approach to make some good stuff  like for every control you can Append some image and show some tool tip, use some nice javascript tool tip etc.</p>
<p>Hope this will help.</p>
<p>Cheers !</p>
<p>AJ</p>
<br />Filed under: <a href='http://abhijitjana.net/category/net-4-0/'>.NET 4.0</a>, <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/jquery/'>jQuery</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2436/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2436&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/03/15/creating-a-simple-context-sensitive-help-for-asp-net-controls-using-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb21.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb22.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb23.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image24.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET Custom Repeater Control with EmptyTemplate, ShowHeaderWhenEmpty,ShowFooterWhenEmpty,ShowCount Properties</title>
		<link>http://abhijitjana.net/2011/03/09/asp-net-custom-repeater-control-with-emptytemplate-showheaderwhenemptyshowfooterwhenemptyshowcount-properties/</link>
		<comments>http://abhijitjana.net/2011/03/09/asp-net-custom-repeater-control-with-emptytemplate-showheaderwhenemptyshowfooterwhenemptyshowcount-properties/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 22:00:54 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[asp.net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[EmptyTemplate]]></category>
		<category><![CDATA[Repeater]]></category>
		<category><![CDATA[Repeater EmptyTemplate]]></category>
		<category><![CDATA[ShowCount]]></category>
		<category><![CDATA[ShowFooterWhenEmpty]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2418</guid>
		<description><![CDATA[If you have worked with ASP.NET GridView Control you must be aware of GridView.EmptyDataTemplate Property  which Gets or sets the user-defined content for the empty data row when a GridView control  data source has no records. Similarly ShowHeaderWhenEmpty property allows you to show or hide the Header row when there is no records. These are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2418&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have worked with <span style="color:#000080;">ASP.NET GridView</span> Control you must be aware of <span style="color:#000080;">GridView.EmptyDataTemplate </span>Property  which Gets or sets the user-defined content for the empty data row when a Gri<a href="http://abhijitjana.files.wordpress.com/2011/03/image9.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;float:right;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb9.png?w=243&h=125" border="0" alt="image" width="243" height="125" align="right" /></a>dView control  data source has no records. Similarly <span style="color:#000080;">ShowHeaderWhenEmpty</span> property allows you to show or hide the Header row when there is no records. These are the really good and very frequent required properties. Now, if you are working with the Repeater Control, it doesn’t have any direct features which enables you to set user define content when data source is empty. In this blog post I will discuss how we can create a custom <span style="color:#000080;">ASP.NET Repeater</span> control with support of <span style="color:#000080;">EmptyTemplate </span>along with few more important features.</p>
<p><span id="more-2418"></span></p>
<p>The basis of the complete implementation is stands on developing a custom ASP.NET Control. Here I will be developing a custom ASP.NET Repeater control which inherits  from <span style="color:#000080;">Repeater </span>as you can see in the bellow code snippet.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image10.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb10.png?w=484&h=122" alt="image" width="484" height="122" /></a></p>
<p>Now, once you inherits you control from default Repeater control, you have access of all methods and properties of Repeater control. The most important thing to here that you need to know about <span style="text-decoration:underline;"><span style="color:#000080;"><em>ITemplate</em> </span></span>Interface. <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.aspx" target="_blank">ITemplate defines the behavior for populating a templated ASP.NET server control with child controls</a> . These <span style="color:#000080;">ITemplate </span>having a method <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.instantiatein.aspx" target="_blank">InstantiateIn</a> which actually instantiate the template with in the control object.  As we required an Template here I created a  properties named “<span style="color:#000080;">EmptyTemplate</span>” of type “<span style="color:#000080;">ITemplate</span>”</p>
<p><pre class="brush: csharp;">
   [PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate EmptyTemplate
        {
            get;
            set;
        }
</pre></p>
<p>In the above code snippets you have notices I have added one attributes as</p>
<p><pre class="brush: csharp;"> PersistenceMode(PersistenceMode.InnerProperty)] </pre></p>
<p>These actually define the type of the property with <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.persistencemode%28VS.71%29.aspx" target="_blank">PersistenceMode</a> Enumeration. <span style="color:#000080;">InnerProperty </span>tells the control that these properties should be used a inner nested tag not as top level attributes.  I discussed about few other values in later part of this article.</p>
<p>Once we are done with the <span style="color:#000080;">Property </span>define , we just need to override the <span style="color:#000080;">CreateChildControls</span>() and <span style="color:#000080;">OnDataBinding</span>() Events.</p>
<p><pre class="brush: csharp;">
     /// &lt;summary&gt;
        /// Creates the child controls.
        /// &lt;/summary&gt;
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            EnabledEmptyTemplate();
        }

        /// &lt;summary&gt;
        /// Raises the DataBinding event.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;e&quot;&gt;An &lt;see cref=&quot;T:System.EventArgs&quot;/&gt; object that contains the event data.&lt;/param&gt;
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            EnabledEmptyTemplate();

        }

        /// &lt;summary&gt;
        /// Enableds the empty template.
        /// &lt;/summary&gt;
        private void EnabledEmptyTemplate()
        {
            if (this.Items.Count &lt;= 0 &amp;&amp; EmptyTemplate != null)
            {
                this.Controls.Clear();

                EmptyTemplate.InstantiateIn(this);

            }
        }
</pre></p>
<p>While overriding those methods, I have internally called a method <span style="color:#000080;">EnabledEmptyTemplate</span>() which actually checks for the Item Counts, if its &amp;lt;=0,  it will Instantiate the <span style="color:#000080;">EmptyTemplate</span>.</p>
<p>That’s all. If you build the control, you will get an Control Icon with in <span style="color:#000080;">ToolBox</span>, which you can directly drag and drop.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image13.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb13.png?w=544&h=192" border="0" alt="image" width="544" height="192" /></a></p>
<p>Now let’s consider you have bellow Student Data Source which you want to bind with this gridview</p>
<p>Sample Student Data Source and binding with repeater</p>
<p><pre class="brush: csharp;">
  public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List&lt;MyClass&gt; names = new List&lt;MyClass&gt;()
            {
            new MyClass { Name =&quot;Student 1&quot;, Address=&quot;Address 1&quot;},
            new MyClass { Name =&quot;Student 2&quot;, Address=&quot;Address 2&quot;},
            new MyClass { Name =&quot;Student 3&quot;, Address=&quot;Address 3&quot;},
            new MyClass { Name =&quot;Student 4&quot;, Address=&quot;Address 4&quot;}
            };
                  ExRepeater1.DataSource = names;
            ExRepeater1.DataBind();
        }
    }

    class MyClass
    {
        public string Name { get; set; }
        public string Address { get; set; }
    }
</pre></p>
<p>Design View for Custom Repeater</p>
<p><pre class="brush: xml;">
    &lt;cc1:ExRepeater ID=&quot;ExRepeater1&quot; runat=&quot;server&quot;  &gt;
            &lt;HeaderTemplate&gt;
                &lt;table&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            Name
                        &lt;/td&gt;
                        &lt;td&gt;
                            Address
                        &lt;/td&gt;
                    &lt;/tr&gt;
                 &lt;/HeaderTemplate&gt;
            &lt;ItemTemplate&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;%#Eval(&quot;Name&quot;)%&gt;
                    &lt;/td&gt;

                    &lt;td&gt;
                        &lt;%#Eval(&quot;Address&quot;)%&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/ItemTemplate&gt;
            &lt;EmptyTemplate&gt;
               &lt;tr&gt;&lt;td&gt; No Records Exist !!!!&lt;/td&gt;&lt;/tr&gt;
            &lt;/EmptyTemplate&gt;
            &lt;FooterTemplate&gt;
            &lt;/table&gt;
            &lt;/FooterTemplate&gt;
        &lt;/cc1:ExRepeater&gt;
</pre></p>
<p>Output</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image14.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb14.png?w=341&h=252" border="0" alt="image" width="341" height="252" /></a></p>
<p>Now, if there is no records in the data source, output will be look like below</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image15.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb15.png?w=333&h=211" border="0" alt="image" width="333" height="211" /></a></p>
<p>Well, this is exactly what we were looking for. So now you have one Template called “<span style="color:#000080;">EmptyTemplate</span>” where you can put what ever the content you want to rendered if the data source is empty.</p>
<h1><span style="color:#000080;">ShowHeaderWhenEmpty </span></h1>
<p>You have noticed, the message <span style="color:#000080;">“No Records Exists”</span> is being displayed along with the header. Now if you want the same features like GridView, that you need control on the showing or hiding header when records is empty.</p>
<p>Let’s add a bool type property with name <span style="color:#000080;">ShowHeaderWhenEmpty ,</span></p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image16.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb16.png?w=463&h=139" alt="image" width="463" height="139" /></a></p>
<p>This properties will accepts a Boolean value based on that Header will be shown. One more point over here is, <span style="color:#000080;"> PersistenceMode.Attribute,</span> which means I am going to use the properties as a top level attributes tag. So <span style="color:#000080;">ShowHeaderWhenEmpty </span><span style="color:#000000;">will be accessible as shown in below</span></p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image17.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb17.png?w=513&h=77" alt="image" width="513" height="77" /></a></p>
<p>Below Snippets describes how to implement the <span style="color:#000080;">ShowHeaderWhenEmpty </span>Properties.</p>
<p><pre class="brush: csharp;">
      /// &lt;summary&gt;
        /// Enableds the empty template.
        /// &lt;/summary&gt;
        private void EnabledEmptyTemplate()
        {
            if (this.Items.Count &lt;= 0 &amp;&amp; EmptyTemplate != null)
            {
                this.Controls.Clear();

                // Instantiate Header Template When Item count 0
                if (ShowHeaderWhenEmpty == true)
                {
                    HeaderTemplate.InstantiateIn(this);
                }

                EmptyTemplate.InstantiateIn(this);
            }
        }
</pre></p>
<h1><span style="color:#000080;">ShowFooterWhenEmpty</span></h1>
<p>Like Header, you can implement the same to show or hide footer when there is no records in repeater.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image18.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb18.png?w=551&h=85" alt="image" width="551" height="85" /></a></p>
<p><pre class="brush: csharp;">
      /// &lt;summary&gt;
        /// Enableds the empty template.
        /// &lt;/summary&gt;
        private void EnabledEmptyTemplate()
        {
            if (this.Items.Count &lt;= 0 &amp;&amp; EmptyTemplate != null)
            {
                this.Controls.Clear();
                EmptyTemplate.InstantiateIn(this);
            // Instantiate Footer Template When Item count 0
                if (ShowFooterWhenEmpty == true)
                {
                    FooterTemplate.InstantiateIn(this);
                }

            }
        }
</pre></p>
<h1><span style="color:#000040;">ShowCount </span></h1>
<p>By this properties I just wanted to show the customization or enhancement idea. Let’s say you want to display the number of total records at the end of the repeater, so by using these properties you can enable or disabled it.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image19.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb19.png?w=337&h=108" border="0" alt="image" width="337" height="108" /></a></p>
<p>If you make it true, you will get the number of records count at the end of repeater records.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image20.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb20.png?w=256&h=233" border="0" alt="image" width="256" height="233" /></a></p>
<p>Below is the implementation for the same.</p>
<p><pre class="brush: csharp;">
      /// &lt;summary&gt;
        /// Enableds the empty template.
        /// &lt;/summary&gt;
        private void EnabledEmptyTemplate()
        {
            if (this.Items.Count &lt;= 0 &amp;&amp; EmptyTemplate != null)
            {
                this.Controls.Clear();

                // Instantiate Header Template When Item count 0
                if (ShowHeaderWhenEmpty == true)
                {
                    HeaderTemplate.InstantiateIn(this);
                }

                EmptyTemplate.InstantiateIn(this);
            }
        }
</pre></p>
<h1><span style="color:#000080;">ShowFooterWhenEmpty</span></h1>
<p>Like Header, you can implement the same to show or hide footer when there is no records in repeater.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/03/image18.png"><img style="display:inline;" title="image" src="http://abhijitjana.files.wordpress.com/2011/03/image_thumb18.png?w=551&h=85" alt="image" width="551" height="85" /></a></p>
<p><pre class="brush: csharp;">
       /// &lt;summary&gt;
        /// Raises the DataBinding event.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;e&quot;&gt;An &lt;see cref=&quot;T:System.EventArgs&quot;/&gt; object that contains the event data.&lt;/param&gt;
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            EnabledEmptyTemplate();
            if (ShowCount == true)
            {

                this.Controls.Add(new LiteralControl(&quot;&lt;br/&gt;Total Number of Records : &quot; + this.Items.Count ));
            }
        }
</pre></p>
<p>Put everything Together :</p>
<p><pre class="brush: csharp;">
// Custom Repeater With EmptyItemTemplate and ShowHeaderWhenEmpty Properties
namespace RepeaterTest
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Web.UI;

    /// &lt;summary&gt;
    /// Advance ASP.NET Repeater with EmptyTemplate, ShowHeaderWhenEmpty, ShowFooterWhenEmpty
    /// &lt;/summary&gt;
    [ToolboxData(&quot;&lt;{0}:ExRepeater runat=server&gt;&quot;)]
    public class ExRepeater : Repeater
    {
        #region Repeater Properties

        /// &lt;summary&gt;
        /// Gets or sets a value indicating whether [show header when empty].
        /// &lt;/summary&gt;
        /// &lt;value&gt;
        /// 	&lt;c&gt;true&lt;/c&gt; if [show header when empty]; otherwise, &lt;c&gt;false&lt;/c&gt;.
        /// &lt;/value&gt;
        [PersistenceMode(PersistenceMode.Attribute)]
        public bool ShowHeaderWhenEmpty
        {
            get;
            set;
        }

        [PersistenceMode(PersistenceMode.Attribute)]
        public bool ShowFooterWhenEmpty
        {
            get;
            set;
        }

        /// &lt;summary&gt;
        /// Gets or sets the empty template.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The empty template.&lt;/value&gt;
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate EmptyTemplate
        {
            get;
            set;
        }

        /// &lt;summary&gt;
        /// Gets or sets the empty template.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The empty template.&lt;/value&gt;
        [PersistenceMode(PersistenceMode.Attribute)]
        public bool ShowCount
        {
            get;
            set;
        }

        #endregion

        #region Repeater Methods

        /// &lt;summary&gt;
        /// Creates the child controls.
        /// &lt;/summary&gt;
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            EnabledEmptyTemplate();
        }

        /// &lt;summary&gt;
        /// Raises the DataBinding event.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;e&quot;&gt;An &lt;see cref=&quot;T:System.EventArgs&quot;/&gt; object that contains the event data.&lt;/param&gt;
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            EnabledEmptyTemplate();
            if (ShowCount == true)
            {

                this.Controls.Add(new LiteralControl(&quot;&lt;br/&gt;Total Number of Records : &quot; + this.Items.Count ));
            }
        }

        /// &lt;summary&gt;
        /// Enableds the empty template.
        /// &lt;/summary&gt;
        private void EnabledEmptyTemplate()
        {
            if (this.Items.Count &lt;= 0 &amp;&amp; EmptyTemplate != null)
            {
                this.Controls.Clear();

                // Instantiate Header Template When Item count 0
                if (ShowHeaderWhenEmpty == true)
                {
                    HeaderTemplate.InstantiateIn(this);
                }

                EmptyTemplate.InstantiateIn(this);
            }
        }

        #endregion
    }
}
</pre></p>
<p><strong><span style="color:#000080;">Summary :</span></strong> In this post I have explained how you can customize your repeater control by adding must needed features likes EmptyTemplate, ShowHeaderWhenEmpty,ShowFooterWhenEmpty,ShowCount.</p>
<p>Hope this will help !</p>
<p>Cheers !</p>
<p>AJ</p>
<br />Filed under: <a href='http://abhijitjana.net/category/net-4-0/'>.NET 4.0</a>, <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/asp-net-4-0/'>ASP.NET 4.0</a>, <a href='http://abhijitjana.net/category/tips-and-tricks/'>Tips and Tricks</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2418/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2418/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2418&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/03/09/asp-net-custom-repeater-control-with-emptytemplate-showheaderwhenemptyshowfooterwhenemptyshowcount-properties/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb13.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb14.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb15.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb16.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb17.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb18.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb19.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb20.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/03/image_thumb18.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Run ASP.NET Web Application from Command Prompt</title>
		<link>http://abhijitjana.net/2011/02/28/run-asp-net-web-application-from-command-prompt/</link>
		<comments>http://abhijitjana.net/2011/02/28/run-asp-net-web-application-from-command-prompt/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 20:18:05 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[codeproject]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2346</guid>
		<description><![CDATA[Visual Studio has its own integrated ASP.NET Runtime engine, which helps to run any ASP.NET web application with in Visual Studio.&#160; While running application from Visual Studio, you must have seen a popup notification in System Tray (As shown in below image) , which is notification of ASP.NET Development Server. This ASP.NET Development Server is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2346&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Visual Studio has its own integrated ASP.NET Runtime engine, which helps to run any ASP.NET web application with in Visual Studio.&#160; While running application from Visual Studio, you must have seen a popup notification in System Tray (As shown in below image) , which is notification of ASP.NET Development Server. </p>
<p><img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image4.png?w=272&h=148" width="272" height="148" /></p>
<p>This ASP.NET Development Server is nothing but a executable file (<font color="#000080">WebDev.WebServer</font>) which used by Visual Studio to execute you web application when it’s running in the context of Visual Studio.&#160; You can find the executable file at <em><strong><u>&lt;\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0&gt;</u></strong></em> . This folder contain two different executable </p>
<ul>
<li><font color="#000040">WebDev.WebServer20.EXE </font></li>
<li><font color="#000040">WebDev.WebServer40.EXE</font> </li>
</ul>
<p>WebDev.WebServer20 is targeted to CLR 2.0, which means all the ASP.NET Application which are targeted till FW .NET 3.5 will be taking care by WebDev.WebServer20.EXE and WebDev.WebServer40.EXE for ASP.NET 4.0 based application.</p>
<p>Now, let’s see how we can use these executable to run an ASP.NET 4.0 Application with out using Visual Studio. <img style="border-style:none;" class="wlEmoticon wlEmoticon-surprisedsmile" alt="Surprised smile" src="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-surprisedsmile.png?w=460" /></p>
<p><span id="more-2346"></span>
<p><strong>Step 1 :</strong> Open the Command Prompt for “Program Files (x86)\Common Files\microsoft shared\DevServer\10.0”</p>
<p><img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image7.png?w=570&h=160" width="570" height="160" /></p>
<p>Easiest way to go there, type Cmd in the address bar ( If you are using Win 7), this will directly open command prompt with exact path .</p>
<p>&#160;<img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image8.png?w=382&h=170" width="382" height="170" /></p>
<p><img style="border-style:none;" class="wlEmoticon wlEmoticon-pointingup" alt="Pointing up" src="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-pointingup.png?w=460" /> Source for this cmd Tip : <a href="http://twitter.com/#!/pbrooks/status/35734806549495808">http://twitter.com/#!/pbrooks/status/35734806549495808</a>&#160;<img style="border-style:none;" class="wlEmoticon wlEmoticon-thumbsup" alt="Thumbs up" src="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-thumbsup1.png?w=460" /></p>
<p><strong>Step 2: [Optional] </strong>Type <u>WebDev.WebServer40</u> and Press <u>Enter</u>, this will open a popup window with the details of required parameter </p>
<p><img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image9.png?w=327&h=338" width="327" height="338" /></p>
<p><strong>Step 3 :</strong> If you are done with review, type below command in your command prompt</p>
<p><img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image10.png?w=591&h=114" width="591" height="114" /></p>
<p><strong>Note :</strong> Port number should be valid and not in used by any other process and path is location of your published web apps.</p>
<p>Step 4: Once done, press Enter, you will see a pop up notification in system tray</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image11.png?w=337&h=105" width="337" height="105" />&#160;</p>
<p>If you double click on that icon you will get below window of ASP.NET Development server, which is exactly same notification window which we used to get when we run some ASP.NET Application from Visual Studio.</p>
<p><img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image12.png?w=280&h=162" width="280" height="162" /></p>
<p>This indicates your application is running now. </p>
<p><strong>Step 4:</strong> Open IE &gt; Type http://localhost:&lt;portnumber&gt; , you are there !<img style="border-style:none;" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-winkingsmile.png?w=460" /></p>
<p><img style="display:inline;" title="image" alt="image" src="http://abhijitjana.files.wordpress.com/2011/02/image13.png?w=405&h=180" width="405" height="180" /></p>
<br />Filed under: <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/tips-and-tricks/'>Tips and Tricks</a>, <a href='http://abhijitjana.net/category/visual-studio/'>Visual Studio</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2346&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/02/28/run-asp-net-web-application-from-command-prompt/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-surprisedsmile.png" medium="image">
			<media:title type="html">Surprised smile</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-pointingup.png" medium="image">
			<media:title type="html">Pointing up</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-thumbsup1.png" medium="image">
			<media:title type="html">Thumbs up</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image11.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image12.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/wlemoticon-winkingsmile.png" medium="image">
			<media:title type="html">Winking smile</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/02/image13.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>How to make ViewState secure in ASP.NET ?</title>
		<link>http://abhijitjana.net/2011/01/26/how-to-make-viewstate-secure-in-asp-net/</link>
		<comments>http://abhijitjana.net/2011/01/26/how-to-make-viewstate-secure-in-asp-net/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 19:43:40 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2302</guid>
		<description><![CDATA[The ASP.NET ViewState is a client side state management.  ViewState is stored in hidden field with ID named __VIEWSTATE. Typically, stored ViewState information  looks as below:   Now let us look at the value. It looks likes an encrypted string. This is nothing but Base64 Encoded string and it is not an encrypted string.  So [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2302&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The ASP.NET ViewState is a client side state management.  ViewState is stored in hidden field with ID named <span style="color:#003366;">__VIEWSTATE</span>. Typically, stored ViewState information  looks as below:</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image38.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb31.png?w=594&h=85" border="0" alt="image" width="594" height="85" /></a> </p>
<p>Now let us look at the value. It looks likes an encrypted string. This is nothing but <span style="color:#003366;">Base64 Encoded </span>string and it is not an encrypted string.  So it can be easily decoded.</p>
<p>The main reasons for making it <span style="color:#003366;">Base64 </span>encoding are as follows:</p>
<p>1.  Base64 makes a string suitable for HTTP transfer</p>
<p>2. It makes it a little harder to read .</p>
<p>But people often get confused that this is an encrypted string.</p>
<p><span id="more-2302"></span></p>
<p>Let us try to decode the string using <span style="color:#003366;">ViewState Decoder</span> <span style="text-decoration:underline;">(A nice tool created by Fritz Onion</span>).</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image39.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb32.png?w=667&h=347" border="0" alt="image" width="667" height="347" /></a></p>
<p>After decoding the string, we can see the exact data that is stored inside the ViewState. </p>
<p>You can write few lines of code to decode the text and you will get the exact view state information.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image40.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb33.png?w=684&h=191" border="0" alt="image" width="684" height="191" /></a></p>
<p>So here is how the ViewState Works,</p>
<p>By default, ViewState is serialized into a base-64 encoded string. On<span style="color:#003366;"> PostBack</span>, the ViewState information is loaded and reapplied to the persisted state of the Control in the Control Hierarchy.</p>
<p>There are two different ways in which you can prevent someone from decrypting the ViewState data.</p>
<p>1. You can make sure that the view state information is tamper-proof by using &#8220;<span style="color:#003366;">hash code</span>&#8220;. You can do this by adding <span style="color:#003366;">&#8220;EnableViewStateMAC=true&#8221;</span> in your page directive. MAC Stands for<span style="color:#003366;"> &#8220;Message Authentication Code&#8221;</span></p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image41.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb34.png?w=530&h=52" border="0" alt="image" width="530" height="52" /></a></p>
<p>When we use <span style="color:#003366;">EnableViewStateMac=”True”,</span> during ViewState save, ASP.NET internally used a hash code. This hash code is a cryptographically strong checksum. This is added with the ViewState content and stored in hidden filed. During  post back, the checksum data is verified again by ASP.NET. If there are some mismatches, Post back will be rejected.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image42.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb35.png?w=589&h=283" border="0" alt="image" width="589" height="283" /></a></p>
<p>2. Second option is to set <span style="color:#003366;">ViewStateEncryptionMode=&#8221;Always&#8221; </span>with your page directives. This will encrypt the view state data. You can do this in the following way:</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image43.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb36.png?w=533&h=50" border="0" alt="image" width="533" height="50" /></a></p>
<p>The ViewStateEncryptionMode has three different options that can be set:</p>
<ul>
<li><span style="color:#003366;">Always :</span> encrypt the view state always</li>
<li><span style="color:#003366;">Auto  :</span> encrypt if any control requests specifically for encryption . For this to happen, the control must call <span style="color:#003366;">Page.RegisterRequiresViewStateEncryption() </span>method to request encryption.</li>
<li><span style="color:#003366;">Never :</span> Never encrypt the ViewState data</li>
</ul>
<p>If you make the <span style="color:#003366;">ViewStateEncryptionMode=&#8221;Always”</span> and try to decode the ViewState data, you will get information as shown below.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image44.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb37.png?w=784&h=215" border="0" alt="image" width="784" height="215" /></a></p>
<p>We can also enable these settings for &#8220;<span style="color:#003366;">EnableViewStateMAC</span>&#8221; and <span style="color:#003366;">ViewStateEncryptionMode</span>&#8221; in<span style="color:#003366;"> <em>web.config</em></span> .</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image45.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb38.png?w=428&h=101" border="0" alt="image" width="428" height="101" /></a></p>
<p><strong><span style="color:#003366;">Note: </span></strong>Try to avoid ViewState Encryption if it is not necessary as it can cause the performance issues.</p>
<p>If you are a beginner with ViewState, please read my article on ViewState &#8211; <span style="font-size:x-small;"><a href="http://www.codeproject.com/KB/aspnet/BegViewState.aspx" target="_blank">Beginner&#8217;s Guide To View State</a> </span></p>
<br />Filed under: <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/tips-and-tricks/'>Tips and Tricks</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2302&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/01/26/how-to-make-viewstate-secure-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb31.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb32.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb33.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb34.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb35.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb36.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb37.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb38.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>When we can use HttpContext.Current.Items to stores data in ASP.NET?</title>
		<link>http://abhijitjana.net/2011/01/14/when-we-can-use-httpcontext-current-items-to-stores-data-in-asp-net/</link>
		<comments>http://abhijitjana.net/2011/01/14/when-we-can-use-httpcontext-current-items-to-stores-data-in-asp-net/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 09:12:00 +0000</pubDate>
		<dc:creator>Abhijit Jana</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[HTTPContext]]></category>
		<category><![CDATA[Session]]></category>

		<guid isPermaLink="false">https://abhijitjana.wordpress.com/?p=2210</guid>
		<description><![CDATA[To answer this question In a single statement, you can use HttpContext.Current.Items for very short term storage. By Short term storage means, this data is valid for a single HTTP Request.  There are many confusion around regarding storing data in HttpContext.Current.Items and storing data in Session variable. In this blog post I am going to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2210&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To answer this question In a single statement, you can use <span style="color:#0000a0;">HttpContext.Current.Items</span> for very short term storage. By Short term storage means, this data is valid for a <span style="color:#0000a0;">single HTTP Request</span>.  There are many confusion around regarding storing data in <span style="color:#0000a0;">HttpContext.Current.Items</span> and <span style="color:#0000a0;">storing data in Session variable</span>. In this blog post I am going to describe what are the different scenarios where we can use <span style="color:#0000a0;">HttpContext.Current.Items</span> and what is the exact difference with session variable.</p>
<p>Items collections of <span style="color:#0000a0;">HttpContext</span> is and <span style="color:#000080;">IDictionary</span> key-value collections and that are shared across a single <span style="color:#000080;">HTTPRequest</span>. Yes, <span style="color:#0000a0;">HttpContext.Current.Items</span>  valid for  a <span style="color:#000080;"><span style="text-decoration:underline;">single HTTPRequest.</span></span>  Once after processing, server  information  is sent back to the browser, the variables that were set in the Items[] collection will lost. Where as for Session Variable, information valid for multiple request as this is user specific. The session variable only  expires either on Session Time Out or explicitly clear the values.</p>
<p><span id="more-2210"></span></p>
<p>Let’s have a quick look how we can store information in in HttpContext.Current.Items</p>
<p><pre class="brush: csharp;">
 HttpContext.Current.Items[&quot;ModuleInfo&quot;] = &quot;Custom Module Info”
 </pre></p>
<p>And retrieve it like</p>
<p><pre class="brush: csharp;">
 string contextData = (string)(HttpContext.Current.Items[&quot;ModuleInfo&quot;]);
 </pre></p>
<p>As I said,  HttpContext.Current.Items, stores data for very limited time period, then when we can use this ?  Yes, This is extremely useful when we can want to share content between <span style="color:#000080;">HttpModule</span> and <span style="color:#000080;">HTTPHandler</span>.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image9.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb9.png?w=129&h=151" alt="image" width="129" height="151" /></a></p>
<p>Because each and every client requests pass through the <span style="color:#000080;">HTTP Pipeline</span> and<span style="color:#000080;"> HTTP Pipeline consists</span> of <span style="color:#000080;">HTTP Module</span> and <span style="color:#000080;">HTTP Handler</span>. So If you are writing one custom HTTP Module by Implementing <span style="color:#000080;">IHttpModule</span> and you want pass some information from this module  to current requested  page or any other module you can use the <span style="color:#000080;">HttpContext.Current.Items</span>  to store the data.</p>
<p><a href="http://abhijitjana.files.wordpress.com/2011/01/image10.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;" title="image" src="http://abhijitjana.files.wordpress.com/2011/01/image_thumb10.png?w=313&h=293" alt="image" width="313" height="293" /></a></p>
<p>Similarly, you use HTTPContext  Items collection when you are sharing same information across the different instance based on the user request and that request could be change for different request.</p>
<p>While using Context Items collections you need to keep one things that, <em>Items collections holds the objects</em>, so you need to do proper <em>type casting while</em> retrieving it.</p>
<p>To Summarize, in ASP.NET <span style="color:#000080;">HttpContext.Current.Items</span> allows us to hold information <span style="text-decoration:underline;">for an single request</span>. We can use it to store short term information. Storing such kind information extremely helpful to send information across different custom modules or to requested pages. You have to make sure that, the data you are using in <em>HttpContext.Current.Items</em>  is only valid for that current request and data should be flashed out automatically when request sent to browser for any new request you have to store the data again. Where as session variable is valid for every request unless session timeout not reached or we are explicitly clear the session.</p>
<p>Hope this will help !</p>
<p>Thanks !</p>
<p>AJ</p>
<br />Filed under: <a href='http://abhijitjana.net/category/my-articles/aspnet/'>ASP.NET</a>, <a href='http://abhijitjana.net/category/asp-net-4-0/'>ASP.NET 4.0</a>, <a href='http://abhijitjana.net/category/tips-and-tricks/'>Tips and Tricks</a>, <a href='http://abhijitjana.net/category/visual-studio/'>Visual Studio</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/abhijitjana.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/abhijitjana.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/abhijitjana.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/abhijitjana.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/abhijitjana.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/abhijitjana.wordpress.com/2210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/abhijitjana.wordpress.com/2210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/abhijitjana.wordpress.com/2210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=abhijitjana.net&#038;blog=6080566&#038;post=2210&#038;subd=abhijitjana&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://abhijitjana.net/2011/01/14/when-we-can-use-httpcontext-current-items-to-stores-data-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d57d87d3990f59469b6b6bd8f03f490?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Abhijit Jana</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://abhijitjana.files.wordpress.com/2011/01/image_thumb10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
