asp.net custom control postback data implementation scheme and code _ practical skills

Source: Internet
Author: User
In a custom control that implements ASP.net, to implement postback or post data for the data, the custom control must implement a IPostBackDataHandler interface in which there are two methods, one of which is LoadPostData, The other is raisepostdatachangedevent. The first method is used to populate the related properties of the custom control when the data is postback, and the second method to fire the control-related events. In other words, these two methods should be called when the data is submitted.

However, when we implement our own controls, we inherit IPostBackDataHandler, but we do find that the program does not invoke the method in IPostBackDataHandler when submitting the data. It has been found that to realize data postback, in addition to implementing the IPostBackDataHandler interface, the control needs to be registered as a control that requires a postback number. To implement registration, you override the OnPreRender method in the custom control and call Page.registerrequirespostback (this) in the method; The wording is as follows:

Copy Code code as follows:

public class Mycontrol:webcontrol, ipostbackdatahandler{

protected override void OnPreRender (EventArgs e)
{
Page.registerrequirespostback (this);

Base. OnPreRender (e);
}

}

By implementing the above code, when the data is submitted, the method of IPostBackDataHandler interface is found and is invoked. Next, how to do, you know AH.

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.