- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Manually updating a page by calling its Update method in Visual Studio .NET
Listing 6.12 Manually updating a page by calling its Update method Encoding PDF 417 In .NET Framework Using Barcode creator for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications. www.OnBarcode.comGS1 128 Drawer In Visual Studio .NET Using Barcode drawer for ASP.NET Control to generate, create UCC-128 image in ASP.NET applications. www.OnBarcode.comprotected void Update_Click(object sender, EventArgs e) { UpdatePanel1.Update(); Update itself UpdatePanel2.Update(); Update other UpdatePanel3.Update(); panels on page } Code 128C Drawer In Visual Studio .NET Using Barcode generation for ASP.NET Control to generate, create ANSI/AIM Code 128 image in ASP.NET applications. www.OnBarcode.comMake 2D Barcode In Visual Studio .NET Using Barcode generator for ASP.NET Control to generate, create Matrix image in ASP.NET applications. www.OnBarcode.comThe first Update method is called for the UpdatePanel that originated the asynchronous postback. Because the ChildrenAsTriggers property was set to False, Paint PDF-417 2d Barcode In Visual Studio .NET Using Barcode encoder for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications. www.OnBarcode.comGenerate GS1 - 13 In VS .NET Using Barcode generator for ASP.NET Control to generate, create European Article Number 13 image in ASP.NET applications. www.OnBarcode.comAdvanced techniques
Print Barcode In VS .NET Using Barcode encoder for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comPaint USPS Intelligent Mail In Visual Studio .NET Using Barcode generator for ASP.NET Control to generate, create USPS Intelligent Mail image in ASP.NET applications. www.OnBarcode.comthe panel s contents can be updated only when its Update method is called. The next few lines call the Update method for other panels on the page to render their contents. The previous sections will serve as a core reference to how the UpdatePanel is used, when you read later chapters. It s time to explore a few more advanced scenarios where you can apply the UpdatePanel. Encode PDF417 In Java Using Barcode printer for Java Control to generate, create PDF417 image in Java applications. www.OnBarcode.comReading PDF 417 In VB.NET Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comAdvanced techniques
Barcode Drawer In Objective-C Using Barcode encoder for iPhone Control to generate, create Barcode image in iPhone applications. www.OnBarcode.comPainting Matrix 2D Barcode In Visual Basic .NET Using Barcode printer for VS .NET Control to generate, create Matrix image in .NET framework applications. www.OnBarcode.comSo far, we ve covered the basics of the UpdatePanel, including its properties, methods, and usage. Most of the time, using the UpdatePanel is as simple as applying some of the techniques demonstrated earlier. But sometimes, more complex situations arise where you can use the UpdatePanel in a more creative fashion. Painting UPC Symbol In Java Using Barcode creation for BIRT Control to generate, create GS1 - 12 image in BIRT reports applications. www.OnBarcode.comDrawing Code 39 Full ASCII In Java Using Barcode creation for Android Control to generate, create Code 3/9 image in Android applications. www.OnBarcode.comRepeating UpdatePanels
Drawing UCC-128 In VB.NET Using Barcode drawer for VS .NET Control to generate, create GS1-128 image in VS .NET applications. www.OnBarcode.comQR-Code Creator In Java Using Barcode generator for Android Control to generate, create QR Code JIS X 0510 image in Android applications. www.OnBarcode.comWhen you re working with repeatable data structures, such as a Repeater, DataList, or GridView, it s usually best to place the entire control in an UpdatePanel instead of each repeated item. However, in some cases you may want a panel around the repeatable item instead. Let s take, for example, a list of stocks in your portfolio. Next to each stock listing, you want a button that updates only that stock price. Listing 6.13 shows the markup listing of the portfolio application. Barcode Decoder In Visual Studio .NET Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comEncoding Code 3/9 In Objective-C Using Barcode generation for iPad Control to generate, create Code39 image in iPad applications. www.OnBarcode.comListing 6.13 Repeating an UpdatePanel
USS Code 39 Decoder In VS .NET Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comCreate UPC Symbol In Objective-C Using Barcode printer for iPhone Control to generate, create UPCA image in iPhone applications. www.OnBarcode.com<asp:ScriptManager ID="ScriptManager1" runat="server" /> <h1>My Portfolio</h1> <asp:XmlDataSource ID="data" runat="server"> <Data> <stocks> <stock name="STOCK1" value="STOCK1" /> <stock name="STOCK2" value="STOCK2" /> <stock name="STOCK3" value="STOCK3" /> <stock name="STOCK4" value="STOCK4" /> </stocks> </Data> </asp:XmlDataSource> List of stocks
<div style="width: 200px; border: 1px solid gray; padding: 5px;"> <asp:Repeater ID="Stocks" runat="server" DataSourceID="data" DataMember="stock"> Partial-page rendering with UpdatePanels
<ItemTemplate> <asp:UpdatePanel ID="UpdatePanel1" runat="server" Repeating UpdateMode="Conditional"> panels <ContentTemplate> <asp:Label runat="server" ID="StockName" Text='<%# Eval("name") %>' /> <asp:Button runat="server" ID="UpdateStock" Text="Update" OnClick="UpdateStock_Click" /> <asp:Label runat="server" ID="StockPrice" Text="" /> </ContentTemplate> </asp:UpdatePanel> </ItemTemplate> <SeparatorTemplate> <hr style="border: 1px dashed gray;" /> </SeparatorTemplate> </asp:Repeater> </div> In this example, an B XmlDataSource stores a simple list of stocks in the portfolio. In the ItemTemplate of the Repeater is the C UpdatePanel control. The panel contains a label for the stock name, a button to update the price, and another label to display the price. The server-side code that updates the price is shown in listing 6.14. Listing 6.14 Updating the stock price
protected void UpdateStock_Click(object sender, EventArgs e) { Button button = (Button) sender; Label price = (Label) button.NamingContainer.FindControl ("StockPrice"); Label stock = (Label) button.NamingContainer.FindControl ("StockName"); price.Text = LookupStockPrice(stock.Text); } private string LookupStockPrice(string name) { string price = "$0.00"; switch (name) { case "STOCK1": price = "$10.45"; break; case "STOCK2": price = "$4.00"; break; Find controls
Update stock price
Advanced techniques
case "STOCK3": price = "$5.58"; break; default: break; } return price; } The server-side implementation B finds the controls in the repeated item, then C calls a private method to look up the stock price and update the label accordingly. For simplicity, you hard-code the values returned from the lookup method. When you run the application and select the first three stocks, you get the results shown in figure 6.6. Again, normally it s best to place an UpdatePanel around a single repeatable control. In the cases where you want to place it around a repeated item, be conscious of the number of items that will be rendered: A strain on performance may occur after some time with a large number of items in a repeatable control. Section 7.3.1 provides more insight into why this happens. Figure 6.6 Repeating UpdatePanel controls
Partial-page rendering with UpdatePanels
Nesting UpdatePanels
In addition to being able to repeat UpdatePanel controls, you can also nest them. This makes sense only if the UpdateMode property of the outer panel is set to Conditional. For example, consider the nested panel implementation in listing 6.15.
|
|