Partial-page rendering with UpdatePanels in Visual Studio .NET

Generation PDF 417 in Visual Studio .NET Partial-page rendering with UpdatePanels

Partial-page rendering with UpdatePanels
Draw PDF417 In VS .NET
Using Barcode creator for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
www.OnBarcode.com
Barcode Generator In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
This should be straightforward so far; we ve introduced the asynchronous trigger and how to add it programmatically and declaratively. But what about controls for which you want a normal postback For example, what if you want a button that is a child of an UpdatePanel to perform a normal postback, resulting in a page refresh when it s clicked This brings us to the other type of trigger you can register with the panel: a postback trigger.
Make DataMatrix In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
www.OnBarcode.com
Generating UPC - 13 In .NET
Using Barcode printer for ASP.NET Control to generate, create EAN13 image in ASP.NET applications.
www.OnBarcode.com
Postback triggers
Barcode Maker In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Printing USS Code 39 In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
www.OnBarcode.com
Postback triggers work like traditional postbacks in ASP.NET. They cause the page to refresh and upload its contents to the server while a new page is eventually returned to the client. In some situations, you may want this behavior for controls that inherently become asynchronous triggers because of their association with an UpdatePanel. For example, when a control is a child of the UpdatePanel, by default it becomes an asynchronous trigger and thus replaces any traditional postbacks that would have occurred. Registering a postback trigger is as easy as an asynchronous trigger. Listing 6.9 demonstrates how to register a child control as a postback trigger programmatically.
1D Drawer In .NET
Using Barcode creator for ASP.NET Control to generate, create 1D Barcode image in ASP.NET applications.
www.OnBarcode.com
ISSN - 10 Creation In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create ISSN image in ASP.NET applications.
www.OnBarcode.com
Listing 6.9 Declaring a child control as a postback trigger
Encode PDF-417 2d Barcode In None
Using Barcode encoder for Office Word Control to generate, create PDF 417 image in Office Word applications.
www.OnBarcode.com
PDF-417 2d Barcode Printer In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create PDF 417 image in VS .NET applications.
www.OnBarcode.com
protected override void OnInit(EventArgs e) { base.OnInit(e); PostBackTrigger trigger = new PostBackTrigger(); trigger.ControlID = "Button1"; UpdatePanel1.Triggers.Add(trigger); }
Barcode Generator In Java
Using Barcode drawer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
2D Drawer In Visual C#.NET
Using Barcode creation for Visual Studio .NET Control to generate, create 2D Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
New postback trigger
Barcode Scanner In .NET Framework
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Paint Data Matrix ECC200 In Visual Studio .NET
Using Barcode encoder for .NET framework Control to generate, create Data Matrix image in Visual Studio .NET applications.
www.OnBarcode.com
Add button to trigger collection
Barcode Drawer In Objective-C
Using Barcode drawer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
PDF 417 Drawer In None
Using Barcode printer for Online Control to generate, create PDF 417 image in Online applications.
www.OnBarcode.com
During the Init event, an instance of a PostBackTrigger is created and initialized to a child in the UpdatePanel by setting its ControlID property. Next, you add it to the collection of UpdatePanelTrigger items in the panel s trigger collection to inform the ScriptManager that this control performs traditional postbacks.
QR Code Generation In Java
Using Barcode printer for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
Barcode Generator In .NET Framework
Using Barcode generation for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
NOTE
Barcode Generation In None
Using Barcode creation for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
Code-39 Reader In VS .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Each UpdatePanel has a collection of triggers of a type called UpdatePanelTriggerCollection. This collection contains items of an abstract class called UpdatePanelTrigger. Because the class is abstract, which means you can t create an instance of it, you can only add items that are of type PostBackTrigger or AsyncPostBackTrigger, because they both inherit from UpdatePanelTrigger.
Triggers
Once more, adding the trigger declaratively is as easy as with an asynchronous trigger; see listing 6.10.
Listing 6.10 Registering a child control as a control that raises a normal postback
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always"> <ContentTemplate> <%= DateTime.Now.ToLongTimeString() %> <asp:Button ID="Button1" runat="server" Text="Update" /> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="Button1" /> Reloads </Triggers> entire page </asp:UpdatePanel>
Excluding the EventName property, a PostBackTrigger is added programmatically and declaratively the same way as an AsyncPostBackTrigger. This covers how triggers are specified with an UpdatePanel. What we have yet to cover is how to manually distinguish when triggers are fired. In some cases, you may not want the contents of an UpdatePanel to be rendered when an asynchronous postback occurs, even when one of its conditions has been met (see Conditional UpdateMode, earlier in the chapter). In addition, you may want to update the contents of another UpdatePanel on the page when a one panel is updated.
Manual triggers
The ChildrenAsTriggers property determines whether postbacks from a child control in an UpdatePanel result in its contents being refreshed. By default, this property is set to True and can be set to False only when the UpdateMode is set to Conditional. Attempting to do so without this condition results in an InvalidOperationException being thrown by the ScriptManager during the page s PreRender event. Setting the property to False allows asynchronous postbacks to occur, but the ScriptManager bypasses any updates to the UpdatePanel that are associated with the postback. Listing 6.11 shows how ChildrenAsTriggers is used declaratively.
Partial-page rendering with UpdatePanels
Listing 6.11 Setting ChildrenAsTriggers to false so as not to initialize triggers
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False"> Reloads <ContentTemplate> entire page <%= DateTime.Now.ToLongTimeString() %> <asp:Button ID="Button1" runat="server" Text="Update" OnClick="Update_Click" /> </ContentTemplate> </asp:UpdatePanel>
Programmatically, you can set this property after the Init event, giving you the luxury of waiting for other events in the page lifecycle to occur before determining if this property should be set:
UpdatePanel1.ChildrenAsTriggers = true;
NOTE
The ScriptManager is responsible for orchestrating the partial-page updates of each UpdatePanel on the page. When it comes time to update the page, it iteratively walks through the list of UpdatePanel controls on the page and invokes the triggers in each one to render its contents. In this case, the internal Initialize method that invokes a trigger isn t called, and the contents for the UpdatePanel remain the same.
The Update method This brings us to the Update method of the UpdatePanel. With the Update method, you can force the contents of an UpdatePanel to render during an asynchronous postback. This includes other UpdatePanel controls on the page, as well, but these panels must have their UpdateMode property set to Conditional in order to successfully update. Listing 6.12 demonstrates an event raised from one UpdatePanel updating itself and other panels on the page.
Copyright © OnBarcode.com . All rights reserved.