ASP. NET component design Step by Step (6)

Source: Internet
Author: User
If a post request is sent to the server on the asp.net page, the framework generates and calls controls according to the event cycle, and controls (if callback is supported) load and return data, the server-side events mapped to the control are like replay of the customer's behavior (the client presses a button, but triggers the click event of the server-side control ). What is the mechanism?
If a control needs to handle the return event, a specific interface IPostBackEventHandler must be implemented:
Public interface IPostBackEventHandler {
Void RaisePostBackEvent (string eventArgument );
}
And another interface:
IPostBackDataHandler
{
Bool LoadPostData (string postDataKey, NameValueCollection postCollection );
Void RaisePostDataChangedEvent ();
}
Once these interfaces are implemented by the control, the page framework automatically calls IPostBackDataHandler of the control after the PostBack data is completed. LoadPostData allows the control to read post data. PostDataKey is the name key of the PostBack data. You can use NameValueCollection [postDataKey] to obtain the value passed to the control by the page framework. The control should read this value and update its internal status to reflect status changes. If the control returns true, the status of the server control changes. The page framework immediately calls the RaisePostDataChangedEvent method of the control. In this case, the control should define the events that cause the server control to provide externally. These events are often the stage of code carefully designed by the control programmer for the aspx programmer who uses the Control key.
Another API, IPostBackEventHandler, is also the API called by the server during callback. We know that each control has a UniqueID. When the client triggers a client event that can cause a return (such as pressing the submit button), the HTTP Post data is naturally sent to the server, when the server page framework performs PostBack processing, it will retrieve whether the control supports the IpostBackEventHandler interface, and immediately call the RaisePostBackEvent method of this interface when finding the UniqueID of the control, the UniqueID control has an event to be captured. Obviously, not all events on the client can be projected to the server, but only events and controls that can trigger Post Back (events that can submit form data to the server. Note that the UniqueID must be consistent with the client on the server side. Otherwise, the event cannot be mapped.

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.