The application of the user-defined control.

Source: Internet
Author: User
Control
User-defined controls in ASP.net feature 1: Implement take; 2: Easy to create (relative to component). The following is a pagination navigation bar of sample, received in Webdiyer, I believe many people have been thunderclap piercing, I do not introduce more. This question is just a simple exercise, with no esoteric algorithms or architectures.

----behindcode----------------------------------------------------------------------------------------------------------- ----

Namespace Gallonkit
{
Using System;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;

<summary>
Summary description of the Pagebar.
</summary>

public delegate void Pagelocalbtn (UINT index);

public class PageBar:System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton btn_fistpage;
protected System.Web.UI.WebControls.LinkButton btn_lastpage;
protected System.Web.UI.WebControls.LinkButton btn_prepage;
protected System.Web.UI.WebControls.LinkButton btn_nextpage;
protected System.Web.UI.WebControls.Label Lb_pagecount;
protected System.Web.UI.WebControls.TextBox Tb_pageindex;
protected System.Web.UI.WebControls.LinkButton btn_local;
Public pagelocalbtn Localbtnclick;


private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page

}

private bool Isuint (string strint)
{
Try
{
UInt. Parse (Strint);
}
catch (Exception e)
{
return false;
}

return true;

}



Public UINT PageIndex
{
get{
if (this. Isuint (This.tb_pageIndex.Text.Trim ()))
return UINT. Parse (This.tb_pageIndex.Text.Trim ());
return 0;
}

set{
if (this. Isuint (value. ToString ()))
This.tb_pageIndex.Text = value. ToString ();
Else
throw new System.Exception ("the page range is not correct!") ");

}
}



Public UINT PageCount
{
Get
{
Object obj = viewstate["pagecount__"];
return (obj = null)? 0: (UINT) obj;
}

Set
{

if (this. Isuint (value. ToString ()))
{
This.lb_PageCount.Text = value. ToString ();
viewstate["pagecount__"] = value;
}
Else
throw new System.Exception ("the page range is not correct!") ");
}

}


Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports the desired method-do not use the Code Editor
Modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This.btn_fistPage.Click + = new System.EventHandler (This.btn_fistpage_click);
This.btn_prePage.Click + = new System.EventHandler (This.btn_prepage_click);
This.btn_nextPage.Click + = new System.EventHandler (This.btn_nextpage_click);
This.btn_lastPage.Click + = new System.EventHandler (This.btn_lastpage_click);
This.btn_local. Click + + new System.EventHandler (This.btn_local_click);
This. Load + = new System.EventHandler (this. Page_Load);

}
#endregion

private void Enableallbtn ()
{
This.btn_fistPage.Enabled = true;
This.btn_lastPage.Enabled = true;
This.btn_prePage.Enabled = true;
This.btn_nextPage.Enabled = true;

}

private void Changebtnstatus (char btnindex)
{
Switch (BTNINDEX)
{
Case ' F ':
this.btn_fistPage.Enabled = false;
this.btn_prePage.Enabled = false;
Break
Case ' L ':
this.btn_nextPage.Enabled = false;
this.btn_lastPage.Enabled = false;
Break
Case ' P ':
this.btn_prePage.Enabled = false;
Break
Case ' N ':
this.btn_nextPage.Enabled = false;
Break
}
}

private void Btn_lastpage_click (object sender, System.EventArgs e)
{
ENABLEALLBTN ();

if (Localbtnclick!= null)
{
Localbtnclick (This.pagecount);
}

This. Changebtnstatus (' L ');
}

private void Btn_fistpage_click (object sender, System.EventArgs e)
{
ENABLEALLBTN ();
if (Localbtnclick!= null)
{
Localbtnclick (1);
}

This. Changebtnstatus (' F ');
}

private void Btn_prepage_click (object sender, System.EventArgs e)
{
ENABLEALLBTN ();

if (Localbtnclick = null) return;
if (this.pageindex>1)
this.pageindex--;
Else
{
This. Changebtnstatus (' P ');
This. Changebtnstatus (' F ');
}

This. Localbtnclick (This.pageindex);

}

private void Btn_nextpage_click (object sender, System.EventArgs e)
{
ENABLEALLBTN ();
if (Localbtnclick = null) return;
if (This.pageindex<this.pagecount)
this.pageindex++;
Else
{
This. Changebtnstatus (' N ');
This. Changebtnstatus (' L ');

}

This. Localbtnclick (This.pageindex);
}

private void Btn_local_click (object sender, System.EventArgs e)
{
ENABLEALLBTN ();
if (This.pageindex <=1)
{
This.tb_pageIndex.Text = "1";
This. Changebtnstatus (' F ');
}
Else
{
if (This.pageindex >= this.pagecount)
{
This.pageindex = This.pagecount;
This. Changebtnstatus (' L ');
}
}

if (Localbtnclick!= null)
Localbtnclick (This.pageindex);

}
}
}
====================aspx file =====================================================



| Home | Front Page | Back Page | Last |1 Go | total pages


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.