« August 2006 | Main

April 11, 2007

Custom Server Controls vs User Control

Custom controls compile to their own .dll file and can be used across applications.
User controls are limited to a single application.

Custom controls require no additional files beyond the .dll and are completely compiled.
User control must be deployed as an .ascx file, and the source code in the .ascx file will be visible to anyone with rights to view the files on the web server.

Custom controls can be display a design-time user interface that mimics what will be displayed at runtime.
User controls are always rendered as generic gray box.

Custom controls can be sized visually.
User controls can be sized only by setting properities.

Code to handle events exposed by custom controls can be largely generated automatically by VS.NET.
You will need to add all code by hand to handle an event exposed by a user control.

One should use a user control when reuse is only across a project.
When the control is used in a second project, take a few hours and turn it into a custom control.

April 10, 2007

RadioButtonList & SelectedValue

Before you want to use SelectedValue, you got to check if there is any item selected.

if(rblGrade.SelectedIndex != -1)

Before you set SelectedValue, you need to check if it is null.

if(dr["gender"] != DBNull.Value)
rblGender.SelectedValue = dr["gender"].ToString();