Asp.net FAQ collection (updated at any time)

Source: Internet
Author: User

I,In which page event does the data source binding occur?

---------------------- Answer Area----------------------

1. execution sequence of Data Binding and related events in Asp.net
If you bind a Data Binding event by specifying a performanceid, data Binding is performed in the prerender phase. The itemcreated event of the
control is performed before data binding of each entry. itemdatabound is performed after data binding is completed.
If the datasource attribute is specified, then, when databind is used to bind the control, in which event the databind statement is located, and in which event the control data is bound
note that after the page is PostBack, if the control enableviewstate = true, the loadstate event is triggered. The itemcreated event of the control is triggered.
However, no data binding is performed at this time. E. item. dateitem is empty. Therefore, you need to consider it carefully.
for manual data binding without using databind When enableviewstate = true, data is not bound after PostBack.
instead, the original control is restored from viewstate.
several SCRIPT tags in aspx
1. <% # %> Asp.net data binding expression, which is executed in the prerender or manual data binding event. The content is the expression (C # does not end with;)
2. <%> it is executed in the render event, and it is already the end. The content is a statement (ending with; in C #)
3. <% = %> executed in the render event. Content is an expression (C # does not end with;)

If you want to execute a batch of statements at the place where the expression is executed, it can be encapsulated into a public method of the page class.

2. Events related to controls and pages in ASP. NET
Control_constructor
Onpreinit
Control_oninit
Oninit
Oninitcomplete
Onpreload
Page_load
Control_onload
Onloadcomplete
Onprerender
Control_onprerender
Control_saveviewstate
Control_saveviewstate
Control_render
Render
Control_onunload
OnUnload

Note that control_saveviewstate is before onUnload.
After saveviewstate, if you change something, it will be invalid.
If PostBack is returned, it will be recovered from viewstate, just like hell.

After binding data, you can change it in the page_prerendercomplete event.

---------------------- End ----------------------

 

Ii. Asp.net 2.0 lifecycle and usage principles of page_load and page_init Methods

---------------------- Answer Area----------------------

Web page lifecycle list:

Preinit (1, 2.0)
-> Initialize theme and apply masterpage and control skin.
-> Init
-> Initcomplete (2.0)
-> If PostBack: Create a subcontrol and load the control/view status.
-> Preload (2.0)
-> Load
-> If PostBack, server events are triggered.
-& Gt; loadcomplete (2.0)
-> If not PostBack, a child control is created.
-> Prerender
-> Prerendercomplete (2.0)
-> Save the control/view status
-> Savestatecomplete (2.0)
-> Render
-> Unload

Note that the events marked in (2.0), that is, the newly added events in ASP. NET 2.0, are only available in the page class and not in the control like other events.

In ASP. NET 2.0, you can enable (default value: True) autoeventwireup to process web page events.ProgramAnd use the method name registered by the event handler implicitly.
The following describes how vs2005 implicitly adds an association for each event:

Event> method name
Page. preinit-> page_preinit
Control. init-> page_init
Page. initcomplete-> page_initcomplete
Page. preload-> page_preload
Control. Load-> page_load
Page. loadcomplete-> page_loadcomplete
Control. prerender-> page_prerender
Control. databinding-> page_databind
Page. prerendercomplete-> page_prerendercomplete
Page. savestatecomplete-> page_savestatecomplete
Control. Unload-> page_unload
Templatecontrol. Error-> page_error
Templatecontrol. aborttransation-> page_aborttransation
Templatecontrol. aborttransation-> ontransationabort
Templatecontrol. committransation-> page_committransation
Templatecontrol. committransation-> ontransationcommit

The base page class calls the hookupautomatichandlers method of the base class templatecontrol at the beginning of the request. This method traverses the method names shown in the preceding table and uses reflection to search for methods with the same name and appropriate feature standards in the programmer's class. If a proper method is found, create a suitable Delegate of the type, use this method to initialize it, and add it to the delegate list. The delegate will be triggered when the event occurs.
These events are triggered by a virtual method of the base class page or a virtual method inherited from the base class control. So there are three ways to register these events: (take the load event as an example)

1. explicitly associate a delegate with an event (usually in the init handler of the webpage)
2. Compile a method named page_load and make its feature mark and event the same
3. Override the override virtual method onload.

Override in these three methods is a little faster, but vs2005 is the second by default.

---------------------- End ----------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.