ASP.NET component design step by step (6)

xiaoxiao2021-03-06  40

Recycling Event Map to Server 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 supported) will load the return data, and mapped into controls The server-side event is as if the customer's customer behavior (the customer presses the next button, "causing the Click event of the server-side control). What is the mechanism? If a control need to deal with the return event, it must implement a specific interface IPostBackEventHandler interfaces: public interface IPostBackEventHandler {void RaisePostBackEvent (string eventArgument);} and another interface: IPostBackDataHandler {bool LoadPostData (string postDataKey, NameValueCollection postCollection); void RaisePostDataChangedEvent ( 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 mentioning that if you want to implement the interface, you need to implement the interface, not the usual interface method name as the same name: void ipostbackevent (String Eventargument) {...} That is, the interface is a page frame Implemented, also by page framework.

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

Public String getPostBackClienthyPerLink (string); add JavaScript: append JavaScript to the beginning of the return from getPostBackeventReference call, so that you can make hyperlink return processing on the server.

Public String getPostBackeventReference (control); public string getpostbackeventreference (control, string); get a reference to the client script function, calling this 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 the script, and the script has the following implicit variables: