1 / 16

Beginning ASP.NET (Part 3) .NET 2.0 Core Libraries

Beginning ASP.NET (Part 3) .NET 2.0 Core Libraries. Tuc Goodwin. Agenda. Overview of ASP.NET Events Quick Demo Strings / Formatted or Otherwise Quick Demo Review Questions. Overview of ASP.NET Events. SILVER - An easy way to remember asp.net lifecycle

montana
Download Presentation

Beginning ASP.NET (Part 3) .NET 2.0 Core Libraries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Beginning ASP.NET (Part 3).NET 2.0 Core Libraries Tuc Goodwin

  2. Agenda • Overview of ASP.NET Events • Quick Demo • Strings / Formatted or Otherwise • Quick Demo • Review • Questions

  3. Overview of ASP.NET Events SILVER - An easy way to remember asp.net lifecycle S – Start I – Initialize L – Load V – Validate E – Event Handling R – Render Adapted from the Code Project article at http://69.10.233.10/KB/aspnet/ASPNET_Page_Lifecycle.aspx

  4. 1. Start This is where page properties such as Request, Response, IsPostBack and UICulture are set. If you need to access or override behavior for this step, use the PreInit method to create or re-create dynamic controls, set a master page or theme or read or set profile property values. Note: If the request is a postback, the values of the controls have not yet been restored from view state. If you set a control property at this stage, its value might be overwritten in the next event.

  5. 2. Initialize This stage is where themes are applied, and unique ids are generated and set for controls. You have access to the Init, InitComplete and PreLoad methods in this stage. Microsoft's recommended usage for these methods is as follows: Init – This event is raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties. InitComplete – This event is raised by the Page object. Use this event for processing tasks that require all initialization be complete. PreLoad - Use this event if you need to perform processing on your page or control before the Load event. After the Page raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.

  6. 3. Load Probably the most utilized by developers. In this stage controls are loaded with information retrieved from view and control states. The OnLoad is the event method that occurs during this stage. This is where you set properties for all of the server controls on your page, request query strings, and establish database connections.

  7. 4. Validate If there are controls that require validation, they are validated here and you can now check the IsValid property of the control. The event associated with this is Validate, which contains one overloaded method that accepts a validation group string. The overloaded method instructs the controls in the specified group to validate.

  8. 5. Event Handling The event handling for server controls occurs during this stage. This means that events such as Click, SelectedIndexChanged, etc are applied to your server controls, and, in the case of a postback, these event handlers are fired by the control.

  9. 5. Event Handling (Part II) The accessible events of note in this stage are as follows: LoadComplete – At this step, all of the controls for the page have been loaded. PreRender – A few things of import happen here. First, the page object will call EnsureChildControls for each control, and finally for the page. Additionally, any data bound control that has a DataSourceID set will call its DataBind method. It is important to note that the PreRender event occurs for each control on the page. At the conclusion of this event, ViewState will be saved for the page and all of the controls. SaveStateComplete– ViewState has been saved. If you have actions that do not require changes to controls but require ViewState to have been saved, you can handle the SaveStateComplete event.

  10. 6. Render Render is not really an event. The page object calls this method on each control, which in turn writes out the HTML markup for the control to the browser. For More information see Microsoft's Developing Custom ASP.NET Server Controls. (http://msdn2.microsoft.com/en-us/library/zt27tfhy.aspx)

  11. 7. Unload This final event occurs first for each control, then, finally, for the page. At this point, all controls have been rendered to the output stream and cannot be changed. During this event any attempt to access the response stream will result in an exception being thrown. This event is primarily for cleanup routines such as closing open database connections, and open file streams, or, event logging and other tasks.

  12. Quick Demo • I will show several events being fired… • I will show the Trace Page level attribute…

  13. Strings / Formatted or Otherwise Formatting strings is a very powerful tool. It allows you to concatenate strings, conversions and provide super formatting easily string.Format("{0:c}",100); //$100.00 string.Format("{0:e}", 32768); //3.276800e_004 string.Format("{0:f}", 345.678); //345.68 string.Format("{0:g}"32768); //32768 string.Format("{0:n}", 32768); //32,768 string.Format("{0:p}", 32768); //32,768%

  14. Review • What did we cover?

  15. Questions

  16. Next Month

More Related