<?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>Jwalin Khatri &#187; Custom Control Property</title>
	<atom:link href="http://jwalin.wordpress.com/tag/custom-control-property/feed/" rel="self" type="application/rss+xml" />
	<link>http://jwalin.wordpress.com</link>
	<description>Don't limit yourself</description>
	<lastBuildDate>Wed, 14 Oct 2009 18:29:15 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='jwalin.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/499eff1ef6b26c8546dbe7bd01c0ac6c?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Jwalin Khatri &#187; Custom Control Property</title>
		<link>http://jwalin.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jwalin.wordpress.com/osd.xml" title="Jwalin Khatri" />
		<item>
		<title>ASP.NET Custom Control Properties</title>
		<link>http://jwalin.wordpress.com/2009/02/03/aspnet-custom-control-properties/</link>
		<comments>http://jwalin.wordpress.com/2009/02/03/aspnet-custom-control-properties/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 16:41:04 +0000</pubDate>
		<dc:creator>jwalin</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Custom Control Property]]></category>
		<category><![CDATA[Nullable Property]]></category>
		<category><![CDATA[Property Pattern]]></category>

		<guid isPermaLink="false">http://jwalin.wordpress.com/?p=80</guid>
		<description><![CDATA[When authoring a custom ASP.NET control, I believe it a best practice to store public properties in the control&#8217;s viewstate. This applies to both controls inheriting from WebControl and to user controls.
[System.ComponentModel.DefaultValue("MyDefault")]
public string MyProperty
{
           get { return ViewState["MyProperty"] as string ?? &#8220;MyDefault&#8221;; }
   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=80&subd=jwalin&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When authoring a custom ASP.NET control, I believe it a best practice to store public properties in the control&#8217;s viewstate. This applies to both controls inheriting from WebControl and to user controls.</p>
<p>[System.ComponentModel.DefaultValue("MyDefault")]<br />
public string MyProperty<br />
{<br />
           get { return ViewState["MyProperty"] as string ?? &#8220;MyDefault&#8221;; }<br />
           set { if (MyProperty != value) ViewState["MyProperty"] = value; }<br />
}</p>
<p>The only thing to remember when using the snippet is if ou use a value type (int, Decimal, etc) you need to change the inner cast to use Nullable, which is really easy in C#. Just type a &#8220;?&#8221; mark as the snippet places the cursor right where you need it when you finish.</p>
<p>  [System.ComponentModel.DefaultValue(42)]<br />
  public int TheMeaningOfLife<br />
  {<br />
            get { return ViewState["TheMeaningOfLife"] as int? ?? 42; }<br />
            set { if (TheMeaningOfLife != value) ViewState["TheMeaningOfLife"] = value; }<br />
  }</p>
Posted in Asp.Net Tagged: Custom Control Property, Nullable Property, Property Pattern <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jwalin.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jwalin.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jwalin.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jwalin.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jwalin.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jwalin.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jwalin.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jwalin.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jwalin.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jwalin.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jwalin.wordpress.com&blog=2317521&post=80&subd=jwalin&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://jwalin.wordpress.com/2009/02/03/aspnet-custom-control-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e4be699abbb541e9c09cfcfce329f194?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jwalin</media:title>
		</media:content>
	</item>
	</channel>
</rss>