Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Tuesday, February 12, 2008

Understanding Default Values for User Web Controls

Understanding default values for User Web Controls can be confusing.
First, there is the DefaultValue for the code behind, which does not act as a default value, but as a default property value for the properties window. Here is the Default Property Value for the properties window set in the ascx.cs page:

[Browsable(true)]
[DefaultValue("")]
public string Text
{
get { return Label.Text; }
set { Label.Text = value;
}
}
Now, what you really want is the default value for the control to be set in the ascx page as follows:

<asp:Label ID="Label" runat="server" Text=""></asp:Label>
You can then manipulate the value in the DataBind, CreateChildControls, or Property section. Be aware that the property section doesn't necessarily fire, hence the need to use the ascx properties.

1 comment:

aparna john said...

Hi, Early on with your planning stage, come up with at least three color schemes in Web Design Cochin. Some of the common are: blue and white; red, yellow and white; and blue, orange and white.Thanks....