.NET famous enterprises into the must-read interview questions

1. Run a list of the life cycle of ASP.NET server controls.

General server control life cycle consists of 11 stages:

///  <Summary> 
/// 1. Initialization
 ///  </ Summary> 
///  <Remarks> 
/// Initialization 1. The main control is completed, the page to its child controls recursively by sequentially call the corresponding methods ProcessRequest the OnInit method;
 /// 2. open the view state tracking control by calling TrackViewState method, so that the value stored in ViewState in the page postback correctly restored to the control.
///  </ Remarks> 
protected  the override  void the OnInit (EventArgs E) 
{ 
    the Write ( " 1. the OnInit " );
     Base .OnInit (E);
     the this .Page.RegisterRequiresPostBack ( the this ); 
} 
///  <Summary> 
// / 2. load view
 ///  </ Summary> 
///  <Remarks> 
/// This phase is performed only when the page is sent back, in fact, no data pages into the view state is present in the first executed, further, the main process to the completion of loading the control view state,
 / // provided that the control is enabled view state, the client request process, the view state is stored in a hidden field and back to the server in order to think again whether to perform page postback event postback.
///  </ Remarks> 
protected  the override  void the LoadViewState ( Object savedState) 
{ 
    the Write ( " 2. the LoadViewState " );
     Base .LoadViewState (savedState); 
} 
///  <Summary> 
/// 3. Data Return Processing
 @ /  </ Summary> 
///  <param name = "postDataKey"> loaded page control client ID, filed </ param> 
/// <param name = "postCollection"> loaded with data submitted by the client </ param> 
///  <Remarks> 
/// This phase is performed only when the page is sent back, the main control data return function is completed, submitted in accordance with the client new value and the old value of the data comparison whether RaisePostDataChangedEvent method
 /// client and modified form data is submitted, will be "&" in the form of spaced apart and tie it to the ID data, the control according to the detected ID is implemented IPostBackDataHandler interfaces, if realized
 /// will call LoadPostData method to refresh the chances of its value.
///  </ Remarks> 
public  BOOL the LoadPostData ( String postDataKey, postCollection the NameValueCollection) 
{ 
    the Write ( " 3. the LoadPostData " );
     return  to true ; 
} 
///  <Summary> 
/// . 4.
 </ the Summary> 
///  <Remarks> 
/// executed first page and then recursively Page_Load event OnLoad event of the control, mainly to complete the creation and initialization control, reducing control client data in accordance with the view state,
 /// often come through IsPostBack Analyzing a page request is the first control or the corresponding code logic processing postback event.
///  </ Remarks> 
protected  the override  void the OnLoad (EventArgs E) 
{ 
    the Write ( " 4. the OnLoad " );
     Base .OnLoad (E); 
} 
///  <Summary> 
/// 5. The return event notifications
 // /  </ the Summary> 
///  <Remarks> 
/// this phase is performed only when the page is posted back, this method is also an interface IPostBackDataHandler way, only when LoadPostData is true, RaisePostDataChangedEvent will be called.
///  </ Remarks>
public  void the RaisePostDataChangedEvent () 
{ 
    the Write ( " 5. The the RaisePostDataChangedEvent " ); 
} 
///  <Summary> 
/// 6. The handling postback events
 ///  </ Summary> 
///  <Remarks> 
/// this stage only executed when the page is posted back, mainly caused by the client postback event, successfully captured the client postback event and processed on the server side. The prerequisite is to achieve IPostBackEventHandler interface
 /// judged according to the parameters eventArgument postback event which control is triggered, and then complete the appropriate event handlers.
///  </ Remarks> 
public  void RaisePostBackEvent ( String eventArgument) 
{ 
    the Write ( " 6. The RaisePostBackEvent " ); 
} 
/// <the Summary> 
/// 7. pre-rendered
 ///  </ the Summary> 
///  <Remarks> 
/// some operations, the appropriate resources to register the control before the completion of the main control is rendered, such as: Javascript scripts and controls hidden fields etc. .
///  </ Remarks> 
protected  the override  void the OnPreRender (EventArgs E) 
{ 
    the Write ( " 7. The the OnPreRender " );
     Base .OnPreRender (E); 
} 
///  <Summary> 
/// 8. The save viewstate
 ///  </ Summary> 
///  <Remarks> 
/// opposite of LoadViewState, complete the main storage page view status information, while the page will be executed when the first request, and only executed if the page LoadViewState postback.
///  </ Remarks>
 the override  Object the SaveViewState () 
{ 
    the Write ( " 8. The the SaveViewState " );
     Base .SaveViewState ();
     return  new new Pair (); 
} 
///  <Summary> 
/// 9. The present
 ///  </ Summary> 
///  <Remarks> 
/// the control characters and text output to the server control output stream, in the form of HTML rendered on the client. For controls, the method can be called RenderControl output stream.
///  </ Remarks> 
protected  the override  void the Render (the HtmlTextWriter Writer) 
{ 
    writer.Write ( "< '! the Click Me' INPUT type = 'Button' name = '{0}' value = style = 'position: Absolute; left: 20px; Top: 280px' the onclick = \ "{. 1} \" /> " ,
         the this .UniqueID, Page.ClientScript.GetPostBackEventReference ( the this , "" )); 
    the Write ( " 9. The the Render " );
     Base .render (Writer); 
} 
///  <Summary> 
/// 10. The unloading
 ///  </ the Summary> 
///  <Remarks> 
/// the main page to complete the clean-up and control of resources, can not be equated to trigger when leaving a page or close the browser to when, because relying page view state so that the two requests appear to be continuous, between two requests is stateless.
 ///  </ Remarks>
protected override void OnUnload(EventArgs e)
{
    Write(" 10. The the OnUnload " );
     Base .OnUnload (E); 
} 
///  <Summary> 
/// 11. The release
 ///  </ Summary> 
///  <Remarks> 
/// free up some resources, such as database connections IO file or stream.
///  </ Remarks> 
public  the override  void the Dispose () 
{ 
    the Write ( " 11. The the Dispose " );
     Base .Dispose (); 
} 
Private  void the Write ( String text) 
{ 
    HttpContext.Current.Response.Write (text + " < br /> ");
}

Note: Page as this type of container server controls have a more refined life cycle stages. For each such control, the only one Init event, and Page controls used to set and refine the template page and the theme of the property PreInit, Init, InitComplete three stages, usually PreInit stage, once in the Init stage will no longer change, Init phase will in turn call the Init event to initialize each child control and set the naming container, and InitComplete phase will enable the control has view state tracking capabilities.

2 . Briefly about the difference between design models and operating mode of the ASP.NET server controls.

Design patterns are designed for developers, so that developers can see in time to show the effect of control to quickly set the properties and behavior of the control, but in the event of certain design mode lifecycle control does not execute (such as OnPreRender, Load, CreateChildControls etc.), does not exist only in the context of an environment variable run mode, but Init, Construct, Render, RenderContents, Dispose and other events will be executed in design mode. As OnPreRender event to introduce some resource files (Javascript / CSS / Pictures), under the IDE design state when the file path is not desirable, it must acquire a virtual server path in the current operating mode. Another example cited in the context of a server control's Page PageLoad event, will also report "can not get information" exception error.

ID 3. Brief server control, and the difference between the ClientID UniqueID.

As each server control by ID, UniqueID and ClientID to uniquely identify, where ID is we named ID, UniqueID is the server ID, ClientID is the client ID, normally controls not as a child control or under the MasterPage, which three are exactly the same, if the control this.UniqueID INamingContainer inherited interfaces, the UniqueID and ClientID parent control will add a different ID respectively delimiter (and $ _) is identified.

Reproduced in: https: //www.cnblogs.com/hmiinyu/p/3586065.html

Guess you like

Origin blog.csdn.net/weixin_34148340/article/details/93901814