Asp.net web page custom page control usage details, asp.net Usage Details
After learning about the custom page control over the past few days, we will record the implementation method. You can perform the following in a test:
1. First create a. ascx file named TurnPage, and then write the interface displayed on the front-end of the control:
2. Then write the corresponding background code in TurnPage. ascx. cs. The Code is as follows:
namespace Web{public delegate void GoToPage(int PageNum);public partial class TurnPage : System.Web.UI.UserControl{ private GoToPage _GoToPage = null; protected void Page_Load(object sender, EventArgs e) { } public void InitControl(GoToPage GP) { _GoToPage = GP; } public int DataCount { get { return Int32.Parse(lbl_TotalCount.Text); } set { lbl_TotalCount.Text = value.ToString(); } } public int CurrPageNum { get { return Int32.Parse(lbl_CurrPage.Text); } set { lbl_CurrPage.Text = value.ToString(); } } public int TotalPageNum { get { return Int32.Parse(lbl_TotalPage.Text); } set { lbl_TotalPage.Text = value.ToString(); } } public int PageSize { get { return Int32.Parse(ddl_PageSize.SelectedValue); } } protected void btn_FristPage_Click(object sender, EventArgs e) { _GoToPage(1); } protected void btn_PrevPage_Click(object sender, EventArgs e) { if (int.Parse(lbl_CurrPage.Text) > 1) _GoToPage(int.Parse(lbl_CurrPage.Text) - 1); else _GoToPage(1); } protected void btn_NextPage_Click(object sender, EventArgs e) { if (int.Parse(lbl_CurrPage.Text) < int.Parse(lbl_TotalPage.Text)) _GoToPage(int.Parse(lbl_CurrPage.Text) + 1); else _GoToPage(int.Parse(lbl_TotalPage.Text)); } protected void btn_LastPage_Click(object sender, EventArgs e) { _GoToPage(int.Parse(lbl_TotalPage.Text)); } public void ControlButtonClick() { if (DataCount > 0) { btn_FristPage.Enabled = true; btn_PrevPage.Enabled = true; btn_LastPage.Enabled = true; btn_NextPage.Enabled = true; } else { btn_FristPage.Enabled = false; btn_PrevPage.Enabled = false; btn_LastPage.Enabled = false; btn_NextPage.Enabled = false; } if (CurrPageNum == 1) { btn_FristPage.Enabled = false; btn_PrevPage.Enabled = false; } if (CurrPageNum == TotalPageNum) { btn_LastPage.Enabled = false; btn_NextPage.Enabled = false; } if (CurrPageNum == 0) { btn_FristPage.Enabled = false; btn_PrevPage.Enabled = false; btn_LastPage.Enabled = false; btn_NextPage.Enabled = false; } } protected void ddl_PageSize_SelectedIndexChanged(object sender, EventArgs e) { _GoToPage(1); } protected void btn_GO_Click(object sender, EventArgs e) { int pageNum; if (int.TryParse(txt_PageNum.Text, out pageNum)) { if (pageNum > TotalPageNum) _GoToPage(TotalPageNum); else if (pageNum < 1) _GoToPage(1); else _GoToPage(pageNum); } }}}
3. the control method is ready. Now you have to reference this control on other pages. The reference method is as follows:
You need to configure it at the end of the page:
4. This is the last step. Write the following statement in the background code on the page where you reference this control:
Success!
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.