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.