Online Book Reader

Home Category

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

By Root 5267 0
though the grid is only a small fragment of it. With partial rendering, you take the preceding markup and just wrap it with an UpdatePanel control, as shown here:

...

In addition, you need to add a ScriptManager control to the page. That’s the essence of partial rendering. And it magically just works. Well, not just magically, but it works.

Note

From this simple but effective example, you might be led to think that you surround the whole body of the page with an UpdatePanel control and you’re done. If you do it this way, it certainly works. It might not be particularly efficient though. In the worst case, you need the same bandwidth as you do with classic ASP.NET; however, you still give your users an infinitely better experience because only a portion of the page actually refreshes. As we’ll learn in the rest of the chapter, partial rendering offers a number of attributes to optimize the overall behavior and performance. However, the majority of users are more than happy with the sole effect of a partial page rendering.

The Programming Interface of the Control


Table 20-5 details the properties defined on the UpdatePanel control that constitute the aspects of the control’s behavior that developers can govern.

Table 20-5. Properties of the UpdatePanel Control

Property

Description

ChildrenAsTriggers

Indicates whether postbacks coming from child controls will cause the UpdatePanel to refresh. This property is set to true by default. When this property is false, postbacks from child controls are ignored. You can’t set this property to false when the UpdateMode property is set to Always.

ContentTemplate

A template property, defines what appears in the UpdatePanel when it is rendered.

ContentTemplateContainer

Retrieves the dynamically created template container object. You can use this object to programmatically add child controls to the UpdatePanel.

IsInPartialRendering

Indicates whether the panel is being updated as part of an asynchronous postback. Note that this property is designed for control developers. Page authors should just ignore it.

RenderMode

Indicates whether the contents of the panel will be rendered as a block

tag or as an inline tag. The feasible values for the property—Block and Inline—are defined in the UpdatePanelRenderMode enumeration. The default is Block.

UpdateMode

Gets or sets the rendering mode of the control by determining under which conditions the panel gets updated. The feasible values— Always and Conditional—come from the UpdatePanelUpdateMode enumeration. The default is Always.

Triggers

Defines a collection of trigger objects, each representing an event that causes the panel to refresh automatically.

A bit more explanation is needed for the IsInPartialRendering read-only Boolean property. It indicates whether the contents of an UpdatePanel control are being updated. From this description, it seems to be a fairly useful property. Nonetheless, if you read its value from within any of the handlers defined in a code-behind class, you’ll find out that the value is always false.

As mentioned, IsInPartialRendering is a property designed for control developers only. So it is assigned its proper value only at rendering time—that is, well past the PreRender event you can capture from a code-behind class. Developers creating a custom version of the UpdatePanel control will likely override the Render method. From within this context, they can leverage the property to find out whether the control is being rendered in a full-page refresh or in a partial rendering operation.

As a page author, if you just need to know whether a portion of a page is being updated as a result of an AJAX postback, you use the IsInAsyncPostBack Boolean property on the ScriptManager control.

Note

Like any other ASP.NET AJAX feature, partial rendering requires a ScriptManager control in the page. It is essential, though, that the EnablePartialRendering property

®Online Book Reader