Last post Mar 26, 2008 03:38 PM by mjhufford
Mar 26, 2008 11:07 AM|mjhufford|LINK
I'm creating a custom web control to display weather from an xml feed. I have a couple questions regarding properties.
1. I have a boolean property called "ShowForecast". If I set the default value to True or False, it always returns false when viewed in the browser. However, if I set the default value to "", it works every time...? I'm curious if anyone can give me
some tips about DefaultValues of properties.
Private _showForecast AS Boolean
<Category("Appearance"), DefaultValue("")> _
Public Property ShowForecast() As Boolean
Set(ByVal value As Boolean)
_showForecast = value
Private _showForecast AS Boolean <Category("Appearance"), DefaultValue(True)> _ Public Property ShowForecast() As Boolean Get Return _showForecast End Get Set(ByVal value As Boolean) _showForecast = value End Set End Property
2. I have a string property with a default value of "Images". I would like "Images" to appear in the property pane the first time the control is dropped onto an aspx/ascx from the toolbox. No matter what I put in the "DefaultValue" field in my code, they
always show up blank. Any thoughts?
Mar 26, 2008 01:25 PM|yorks|LINK
The default value attribute does not actually set the default value for the property as you would think (see
http://support.microsoft.com/kb/311339) So if you want the _showForecast to default to true, you need to initialize the _showForecast variable to true. Then, by setting the default value attribute to true,
the IDE will not bold it in the properties pane and the extra code will not be generated. If you change the value to false in the IDE, you will see it is in bold and the property will be generated in the code.
Hope that helps.
Mar 26, 2008 03:38 PM|mjhufford|LINK
That's exactly what I was looking for...thanks!