Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [122]

By Root 5485 0
a protected Boolean property named IsViewStateEnabled. As you can figure out, this property indicates whether view state is working or not for the control. Because of the weird behavior of EnableViewState, it might paradoxically occur that for the same control to have the property IsViewStateEnabled set to true and the property EnableViewState set to false! Specifically, this happens when you try to programmatically disable the view state for a control whose parent (for example, the page) has the view state enabled.

Visibility of a Server Control


If you set Visible to false, ASP.NET doesn’t generate any markup code for the control. However, having Visible set to false doesn’t really mean that no path in the control’s code can output text. The control is still an active object that exposes methods and handles events. If a method, or an event handler, sends text directly to the output console through Response. Write, this text will be displayed to the user anyway. A control with the Visible attribute set to false is still part of the page and maintains its position in the control tree.

Methods of the Control Class


The methods of the Control class are listed and described in Table 6-4.

Table 6-4. Public Methods of a Server Control

Method

Description

ApplyStyleSheetSkin

Applies the properties defined in the page style sheet to the control. The skin properties used depend on the SkinID property.

DataBind

Fires the OnDataBinding event and then invokes the DataBind method on all child controls.

Dispose

Gives the control a chance to perform clean-up tasks before it gets released from memory.

Focus

Sets the input focus to the control.

FindControl

Looks for the specified control in the collection of child controls. Child controls not in the Controls collection of the current controls—that is, not direct children—are not retrieved.

GetRouteUrl

Gets the URL that corresponds to a set of route parameters. This method requires ASP.NET 4.

GetUniqueIDRelativeTo

Returns the prefixed portion of the UniqueID property of the specified control.

HasControls

Indicates whether the control contains any child controls.

RenderControl

Generates the HTML output for the control.

ResolveClientUrl

Use this method to return a URL suitable for use by the client to access resources on the Web server, such as image files, links to additional pages, and so on. It can return a relative path. The method is sealed and can’t be overridden in derived classes.

ResolveUrl

Resolves a relative URL to an absolute URL based on the value passed to the TemplateSourceDirectory property.

SetRenderMethodDelegate

Internal use method, assigns a delegate to render the control and its content into the parent control.

Each control can have child controls. All children are stored in the Controls collection, an object of type ControlCollection. This collection class has a few peculiarities. In particular, it post-processes controls that are added to, and removed from, the collection. When a control is added, its view state is restored if needed and view state tracking is turned on. When a control is removed, the Unload event is fired.

Events of the Control Class


The Control class also defines a set of base events that all server controls in the .NET Framework support.

Table 6-5. Events of a Server Control

Event

Description

DataBinding

Occurs when the DataBind method is called on a control and the control is binding to a data source

Disposed

Occurs when a control is released from memory—the last stage in the control life cycle

Init

Occurs when the control is initialized—the first step in the life cycle

Load

Occurs when the control is loaded into the page; occurs after Init

PreRender

Occurs when the control is about to render its content

Unload

Occurs when the control is unloaded from memory

All server controls are rendered to HTML using the RenderControl method and, when this happens, the PreRender event is fired.

Other Features


Server controls also support some features

Return Main Page Previous Page Next Page

®Online Book Reader