It is simpler to load controls dynamically in the ASP.net, where I'm talking about loading the user control, which is typically loaded with a postback event in the user control, which needs to keep the new data back.
First to build the paging user control, because the previous articles are talking about these things, so directly to the change, pagination code can view the above article 1, article 2, the following is a part of the user control code.
public class PagingControl:System.Web.UI.UserControl
On top we noticed that in the page load event, we judged if (! Page.IsPostBack) to prevent two binding when the postback is loaded, because the first time is completely unnecessary and ultimately is determined by the binding in Lbtnnavigation_click.
Assuming that Pagingcontrol.ascx is the file name of the user control above, and that the page file is in the same directory as the page, the following is the code for the aspnetcommonpaging.aspx file, and in order to load dynamically, a placeholder control is placed on the pages to load the previous user control.
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}
The PlaceHolder1.Controls.Add (Page.LoadControl ("~/pagingcontrol.ascx")) is where the Pagingcontrol user control is loaded onto the current page. If you do not want to use placeholder, we can also use other container controls, just add to the Controls collection.
Note that if you do this in this way, it will not be loaded when the page is back, and then the paging event will not be triggered.
First time: Page OnInit event--> control oninit Event à page Page_Load event à control Page_Load event.
Paging Postback: Page OnInit event--> control oninit Event à page Page_Load event à control Page_Load event Àlbtnnavigation_click paging event.
I think it is important to understand the sequence of events in order to interoperate with multiple controls, and also to help the optimizer improve performance.
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