ASP.NET component design step by step (6)

xiaoxiao2021-03-06  41

Recycling event mapped to server end event

ASP.NET page If you are requesting the server through the POST request, the framework will follow the event cycle generation, call the control, and the control (if you support back), the return data will be loaded, and the server-side event of the control is mapped, it is like Play the customer's customer behavior (the customer presses a button, causing the Click event of the server-side control). What is the mechanism?

If a control needs to handle the return event, you must implement a specific interface iPostBackeventHandler interface:

Public interface ipostbackeventhandler {

Void RaisePostBackeVent (String Eventargument);

}

And another interface:

IPostBackDataHandler

{

Bool LoadPostData (String PostDataKey, NameValueCollection PostCollection);

Void raisepostdataachangedevent ();

}

Once the control implements these interfaces, the page framework will automatically call the control for this interface iPostBackDataHandler after the Postback data is complete. LoadPostData, allows controls to read data from POST. PostDataKey is named key name in Postback data, and the page frame is passed to the value of the control through NameValueCollection [PostDataKey]. The control should read this value and perform its own internal status update, reflect the state change. If the control returns true, it indicates that the server control status changes, and this time the page frame will call the RaisePostDataChangeDevent method for this control. At this point, the control should define the event that the server controls are triggered. These events are often a Code Stage for the control programmer carefully designed ASPX programmer who uses this control button.

As for another interface ipostbackeventhandler, it is also an interface for the server call. We know that every control has a UniqueID, when the client triggers a client event that can cause the return (for example, press the Submit button), then natural http post data to the server side, the server page frameworks to postback, The retrieval of whether the control supports the iPostBackeventHandler interface, and the uniqueid discovery support for the finding control immediately calls the RaisePostBackevent method of this interface, indicating that the UniqueId control has a captured event. Obviously, not all events can be projected to the server side, which can only be able to raise the post back (which is an event capable of submitting a form data to the server). Note that the uniqueID here must be consistent with the server side and the client, otherwise the event cannot be mapping.

It is worth noting that the controller is that if you want to implement the interface, you need to implement the interface, not the usual interface method name:

Void ipostbackeventhandler.raisepostbackevent (String Eventargument)

{

......

}

That is, the interface is implemented for the page framework, and is also called by the page frame.

On the other hand, on the client, it can cause only 2 HTML elements of the backhaul "INOPUT TYPE = Submit> and

Control Control,

String argument

);

Get reference to the client script function, which will cause the server to return to the form when called.

Public String GetPostbackClienTheperLink

Control Control,

String argument

); Pather JavaScript: append to the beginning of the return from the getPostBackeventReference call, so that the server can make hyperlink return processing.

Public String getPostBackeventReference (Control);

Public String getPostBackeventReference (Control, String);

Get a reference to the client script function, calling the function will make the server

If a control determines that the above method ensures that the client triggers an email, the control reference page will result in the final output to the client's HTML containing scripts, and the script has the following implicit variables: