Beginning Ajax with ASP.NET- P17
Số trang: 15
Loại file: pdf
Dung lượng: 412.75 KB
Lượt xem: 12
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Beginning Ajax with ASP.NET- P17:Thank you for purchasing Beginning Ajax with ASP.NET. We know that you have a lot of options whenselecting a programming book and are glad that you have chosen ours. We’re sure you will be pleasedwith the relevant content and high quality you have come to expect from the Wrox Press line of books.
Nội dung trích xuất từ tài liệu:
Beginning Ajax with ASP.NET- P17Chapter 9 Switch back to the design view and double-click the btnLongRequest button. This action will switch you to the code window and wire up a button click event method. Update the Manager class by inheriting from the ComfortASP.ComfortASP_Page class. The only other changes required for this demonstration are to add a short delay when the button is clicked and to print a message on the label when the request is completed. Notice that you are not setting the page’s HiddenFormPostBack property. The ComfortASP.NET Manager control is responsible for notifying the application that this page is Ajax-enabled. public partial class Manager : ComfortASP.ComfortASP_Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnLongRequest_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(5000); this.lblResult.Text = “Done”; } } Now run the page to demonstrate its behavior. Experiment with the manager settings by changing the HiddenRequestTimeout property to 3 in the ASPX file. This allows the page to time out before the server is done processing, and you see how the framework will notify the user of a timeout. Change the DisableFormWhilePostBack property, and note how the controls on the page are no longer disabled when you make a call to the server. Finally, you can see the effect of the TransferDifference property by setting it to false and clicking on the button. The ComfortASP.NET demo version includes a bar graph that represents the amount of information sent across the wire. When TransferDifference is turned off, you can see by the graph how much more data is transported to the client.Example 4: PanelUpdater Control (Periodic Refresh) The ComfortASP.NET PanelUpdater is a control that allows you to target specific areas of a page to update. You may decide that you want to change the contents of a section of your page, but the rest of the page should remain unchanged. The PanelUpdater wraps up many of the implementation details, allowing you to easily access page segments. The PanelUpdater works by being nested within an ASP.NET Panel control. The panel acts as the overall container and the PanelUpdater, simply by being placed inside the panel, will expose the con- tainer to ComfortASP.NET. The control exists on the page to service interaction between the browser and the server and will not render anything visible to the user. The ComfortASP.NET PanelUpdater is associated to its parent panel, so you may have multiple Panel/PanelUpdater combinations on a single page.216 Other Ajax Frameworks for .NETImagine for a moment that you want to create a page that will continually engage with the server to seeif there are new messages available for the user. The PanelUpdater is a perfect choice for a requirementlike this for two reasons: ❑ Reason one is that the control will allow you to target a portion of the page and allow the system to update only that region of the page you have specified. ❑ Reason two is that the PanelUpdater features a timer interval that, once set, will instruct the control to send requests to the server at every n number of seconds. This pattern is known as the Periodic Refresh pattern, and you will also implement this same behavior in the next section, using MagicAjax.The following example implements a page with the requirements just described. Figure 9-5 is an exampleof how the finished product will look. Figure 9-5 The ComfortASP.NET demo version will automatically print the bar graph at the top of the page, indicat- ing the amount of data transferred with a link back to the ComfortASP.NET web site. The full version does not have this feature.The page includes a panel that will contact the server every 3 seconds to update the page with the newmessage count. 217Chapter 9Try It Out Using PanelUpdater Control Begin by adding a new web form to the solution, naming it PanelUpdater.aspx. Make sure that you are in source view, and add the following line after the Page directive line found at the top of the ASPX page. The Register tag will make the ComfortASP.NET framework available to the page. Continue by adding the following markup between the tags: Message Count: The ASP.NET panel is the container for the section of the page to update. The ComfortASP.NET PanelUpdater control will handle generating the client-side code to create the timeout behavior. Be sure to activate the PanelUpdater by setting the Active property equal to true. The TimerIntervalUpdate property will take a value for the number of seconds you want the browser to wait before contacting the server. Finally, the label at the end of the listing will take the latest information from the server and print the message count back to the user. Now switch to the code window to update the PanelUpdater class. public partial class PanelUpdater : ComfortASP.ComfortASP_Page { private int MessageCount { get { if (this.ViewState[“messageCount”] == null) { return 0; } else { return Convert.ToInt32(this.ViewState[“messageCount”]); } } set { this.ViewState.Add(“messageCount”, value);218 ...
Nội dung trích xuất từ tài liệu:
Beginning Ajax with ASP.NET- P17Chapter 9 Switch back to the design view and double-click the btnLongRequest button. This action will switch you to the code window and wire up a button click event method. Update the Manager class by inheriting from the ComfortASP.ComfortASP_Page class. The only other changes required for this demonstration are to add a short delay when the button is clicked and to print a message on the label when the request is completed. Notice that you are not setting the page’s HiddenFormPostBack property. The ComfortASP.NET Manager control is responsible for notifying the application that this page is Ajax-enabled. public partial class Manager : ComfortASP.ComfortASP_Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnLongRequest_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(5000); this.lblResult.Text = “Done”; } } Now run the page to demonstrate its behavior. Experiment with the manager settings by changing the HiddenRequestTimeout property to 3 in the ASPX file. This allows the page to time out before the server is done processing, and you see how the framework will notify the user of a timeout. Change the DisableFormWhilePostBack property, and note how the controls on the page are no longer disabled when you make a call to the server. Finally, you can see the effect of the TransferDifference property by setting it to false and clicking on the button. The ComfortASP.NET demo version includes a bar graph that represents the amount of information sent across the wire. When TransferDifference is turned off, you can see by the graph how much more data is transported to the client.Example 4: PanelUpdater Control (Periodic Refresh) The ComfortASP.NET PanelUpdater is a control that allows you to target specific areas of a page to update. You may decide that you want to change the contents of a section of your page, but the rest of the page should remain unchanged. The PanelUpdater wraps up many of the implementation details, allowing you to easily access page segments. The PanelUpdater works by being nested within an ASP.NET Panel control. The panel acts as the overall container and the PanelUpdater, simply by being placed inside the panel, will expose the con- tainer to ComfortASP.NET. The control exists on the page to service interaction between the browser and the server and will not render anything visible to the user. The ComfortASP.NET PanelUpdater is associated to its parent panel, so you may have multiple Panel/PanelUpdater combinations on a single page.216 Other Ajax Frameworks for .NETImagine for a moment that you want to create a page that will continually engage with the server to seeif there are new messages available for the user. The PanelUpdater is a perfect choice for a requirementlike this for two reasons: ❑ Reason one is that the control will allow you to target a portion of the page and allow the system to update only that region of the page you have specified. ❑ Reason two is that the PanelUpdater features a timer interval that, once set, will instruct the control to send requests to the server at every n number of seconds. This pattern is known as the Periodic Refresh pattern, and you will also implement this same behavior in the next section, using MagicAjax.The following example implements a page with the requirements just described. Figure 9-5 is an exampleof how the finished product will look. Figure 9-5 The ComfortASP.NET demo version will automatically print the bar graph at the top of the page, indicat- ing the amount of data transferred with a link back to the ComfortASP.NET web site. The full version does not have this feature.The page includes a panel that will contact the server every 3 seconds to update the page with the newmessage count. 217Chapter 9Try It Out Using PanelUpdater Control Begin by adding a new web form to the solution, naming it PanelUpdater.aspx. Make sure that you are in source view, and add the following line after the Page directive line found at the top of the ASPX page. The Register tag will make the ComfortASP.NET framework available to the page. Continue by adding the following markup between the tags: Message Count: The ASP.NET panel is the container for the section of the page to update. The ComfortASP.NET PanelUpdater control will handle generating the client-side code to create the timeout behavior. Be sure to activate the PanelUpdater by setting the Active property equal to true. The TimerIntervalUpdate property will take a value for the number of seconds you want the browser to wait before contacting the server. Finally, the label at the end of the listing will take the latest information from the server and print the message count back to the user. Now switch to the code window to update the PanelUpdater class. public partial class PanelUpdater : ComfortASP.ComfortASP_Page { private int MessageCount { get { if (this.ViewState[“messageCount”] == null) { return 0; } else { return Convert.ToInt32(this.ViewState[“messageCount”]); } } set { this.ViewState.Add(“messageCount”, value);218 ...
Tìm kiếm theo từ khóa liên quan:
nhập môn lập trình kỹ thuật lập trình lập trình flash lập trình web ngôn ngữ html lập trình hướng đối tượngGợi ý tài liệu liên quan:
-
Đề cương chi tiết học phần Cấu trúc dữ liệu và giải thuật (Data structures and algorithms)
10 trang 301 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 254 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 244 0 0 -
101 trang 193 1 0
-
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 179 0 0 -
Giới thiệu môn học Ngôn ngữ lập trình C++
5 trang 177 0 0 -
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 146 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 142 0 0 -
Giáo trình nhập môn lập trình - Phần 22
48 trang 135 0 0 -
14 trang 128 0 0