first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

MCAD/MCSD Notes: Chapter 4, Lesson 1; Using Controls

Lesson 1: Using Controls

This lesson really begins to examine ASP.NET 1.X technology. Controls are the centerpiece of this technology. The first sentence of this lesson says, "Controls are the tools for all the tasks you perform on a Web form."

There are two ways to arrange controls on a Web form, Grid layout and Flow layout. There are two types of controls, Server controls and HTML controls.

HTML controls are more efficient than Server controls when using data binding. "...it's more efficient not to maintain state information for bound controls." This reinforces the opinion here that HTML controls should have precedence over Server controls in Web forms design.

For some reason, the Literal control corresponds with the Horizontal Rule HTML control in Table 4-2. The opinion here is that Literal control along with the Placeholder control are the two most useful Server controls. This begs the question, 'Why is the Literal control omitted from the "Working with Text" section?'

Add static items to the ListBox, DropDownList and Table controls with the Collection Editor from the Properties pane at design time. Add items at runtime via the Add() method of the Items collection of the ListBox and DropDownList controls---and the Add() methods of the Rows and Cells collections of a Table control.

This is the first example in the book that demonstrates the limitations of ViewState because, evidently, the Table control Rows and Cells collections cannot be serialized and stored between requests (probably for performance reasons). In fact, the RebuildTable() routine in the code samples is a design pattern for manually manipulating ViewState to maintain state for controls that are not adequately supported.

When an Item is not selected, the SelectedItem property returns null (or Nothing in VB.NET).

At design time data bindings can be defined in the DataBindings dialog box. The Custom binding expression option is used quite frequently and should naturally lead to the subject "Data Binding Expression Syntax" covered here:

http://msdn.microsoft.com/
    library/en-us/cpgenref/html/
        cpconDatabindingExpressionSyntax.asp

This in turn will lead to inline blocks like this:

<asp:DropDownList id="DropDownList1" runat="server" DataSource="<%# arrData %>">
</asp:DropDownList>

where the delcared attribute DataSource="<%# arrData %>" is rendered in HTML like this:

&lt;select name=&quot;DropDownList1&quot; id=&quot;DropDownList1&quot;&gt;
    &lt;option value=&quot;This&quot;&gt;This&lt;/option&gt;
    &lt;option value=&quot;that&quot;&gt;that&lt;/option&gt;
    &lt;option value=&quot;and&quot;&gt;and&lt;/option&gt;
    &lt;option value=&quot;the&quot;&gt;the&lt;/option&gt;
    &lt;option value=&quot;other&quot;&gt;other&lt;/option&gt;
&lt;/select&gt;

Keep in mind that the same declaration can cause this to render:

&lt;select name=&quot;DropDownList1&quot; id=&quot;DropDownList1&quot;&gt;
&lt;/select&gt;

This happens when the DataBind() method is not called before the Web form loads.

This implies that using data binding and ViewState for a control reduces performance and can be redundant. However, in the following lines of code, SelectedIndex will always be -1 when ViewState is turned off:

if(this.IsPostBack)
{
    int idx = this.DropDownList1.SelectedIndex;
    this.DataBind();
    this.DropDownList1.SelectedIndex = idx;
}
else
    this.DataBind();

The conclusion can be turn ViewState off when using data bound controls to display reports but leave it on for round-tripping (required for many editing scenarios).

What resonates here is the wording, "a template is a declaration of HTML formatting" that will be repeated for each data item. This reminds me that Visual Studio saves my template "drawing" as ASP.NET tags in the HTML source. This is a superior alterative to the code auto-generated and hidden in a region in Windows forms applications.

This is done through code-generating hookups to Javascript files installed by ASP.NET under a folder called \\aspnet_client.

Yes. And this capability is pretty cool! A server-side image map handler can be set up with the ImageButton control because System.Web.UI.ImageClickEventArgs has X and Y properties to capture mouse clicks. See:

http://msdn.microsoft.com/library/
    en-us/cpgenref/html/cpconimagebuttonwebcontrol.asp

The RadioButtonList and CheckboxList controls solve the problem of toggling among a group of controls. Optionally, the RadioButton control has a GroupName property to allow toggling among a non-columnar list of radio buttons. The Checkbox control does not have such a property for grouping.

The Background property of a Web form, the Image, ImageButton and the XML-driven AdRotator controls handle displaying graphics.

This control solves the problem of hiding and showing groups of controls (as it renders as the HTML div element). It only supports Flow layout.

A pleasant surprise in this server control is its ability to select multiple dates. The following code sample run during the SelectionChanged event handles both single and multiple date selections:

if (calSource.SelectedDates.Count == 1)
// If one date is selected, display it.
lblDate.Text = &quot;Selected date: &quot; + calSource.SelectedDate;
else
// If multiple dates are selected, display them.
lblDate.Text = String.Format(&quot;Selected dates: {0} to {1}.&quot;,
        calSource.SelectedDates[0],
        calSource.SelectedDates[calSource.SelectedDates.Count - 1]);

This is a composite HTML control---not a server control. Trying and catching a System.UnauthorizedAccessException exception is good design. The HttpPostedFile object of the HtmlInputFile.PostedFile property has a ContentLength property to check the size of a file before saving it to server disk.

mod date: 2005-04-08T23:47:30.000Z