Implementation Method and code of asp.net without refreshing pages

Source: Internet
Author: User

I saw a custom page control two days ago. Like AspNetPager, it implements the IPostBackEventHandler interface, but it is much simpler. Can I think that the ICallbackEventHandler interface cannot be implemented without refreshing new pages? When I think of it, I will do it right away. Finally, the idea has become a reality !!
I personally like to use Repeater. Because of its conciseness, this AjaxPager is targeted to Repeater!
Step by step:
Code
The Code is as follows:
[DefaultProperty ("TotalRecord "),
ToolboxData ("<{0}: AjaxPager runat = server> </{0}: AjaxPager>")]
Public class AjaxPager: WebControl, ICallbackEventHandler
{
Public AjaxPager ()
: Base (HtmlTextWriterTag. Div)
{
This. Load + = new EventHandler (AjaxPager_Load );
}
Void AjaxPager_Load (object sender, EventArgs e)
{
String script = "function AjaxPagerCallBack (returnData) {var parts = returnData. split ('[_]'); document. getElementById ('"+ this. uniqueID. replace ('$', '_') + "'). innerHTML = parts [0]; document. getElementById ('"+ Info. containID + "'). innerHTML = parts [1]} ";
This. Page. ClientScript. RegisterClientScriptBlock (this. Page. GetType (), "AjaxPagerCallBack", script, true );
}
}

Here, a piece of JS Code is registered to the page in the Load event. The AjaxPagerCallBack method performs two operations and puts the data presented by itself into the DIV container generated by the client, that is, the id is this. uniqueID. replace ('$', '_') div, ClientID seems OK! Haha, confused for a moment! The second step is to put the paging data in the div with the id Info. ContainID, which will be discussed below the Info Object.
Variable attributes
The Code is as follows:
# Region variable
Private string _ BarBackGroundColor = "# FFFFFF ";
Private string _ BarLinkColor = "Navy ";
Private string _ BarCurrentColor = "# EEEEEE ";
Private int _ TotalRecord = 50;
Private int _ TotalPage = 0;
Private int _ CurrentIndex = 1;
Private int _ ItemSize = 10;
Private PageInfo _ Info = new PageInfo ();
# Endregion
# Region attributes
# Region appearance
[Description ("Page background color "),
Bindable (true ),
Category ("appearance "),
DefaultValue ("# FFFFFF")]
Public string BarBackGroundColor
{
Get {return _ BarBackGroundColor ;}
Set {_ BarBackGroundColor = value ;}
}
[Description ("pagination bar link digit color "),
Bindable (true ),
Category ("appearance "),
DefaultValue ("Navy")]
Public string BarLinkColor
{
Get {return _ BarLinkColor ;}
Set {_ BarLinkColor = value ;}
}
[Description ("number color of the current page of the paging bar "),
Bindable (true ),
Category ("appearance "),
DefaultValue ("# EEEEEE")]
Public string BarCurrentColor
{
Get {return _ BarCurrentColor ;}
Set {_ BarCurrentColor = value ;}
}
# Endregion
# Region Behavior
[Description ("Total number of records "),
Category ("behavior "),
DefaultValue (50)]
Public int TotalRecord
{
Get {return _ TotalRecord ;}
Set
{
_ TotalRecord = value;
}
}
[Description ("Total pages "),
Category ("behavior "),
DefaultValue (0)]
Public int TotalPage
{
Get {return _ TotalPage ;}
}
[Description ("Bar size "),
Category ("behavior "),
DefaultValue (10)]
Public int BarSize
{
Get {return _ ItemSize ;}
Set
{
Foreach (char c in System. Convert. ToString (value ))
{
If (! Char. IsNumber (c ))
{
_ ItemSize = 10;
Break;
}
}
_ ItemSize = value;
}
}
[Description ("Current page value "),
Category ("behavior "),
DefaultValue (1)]
Public int PageIndex
{
Get {return _ CurrentIndex ;}
Set {_ CurrentIndex = value ;}
}
# Endregion
Public PageInfo Info
{
Get {return _ Info ;}
Set {_ Info = value ;}
}
# Endregion

  • Four pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • 4
  • Next Page

Related Article

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.