Jquery AJAX.ASHX Efficient Paging implementation code _jquery

Source: Internet
Author: User
Tags httpcontext rowcount
I used to use the UpdatePanel updateprogress and other controls, and even to the extent of abuse, just blindly pursuit of no refresh, while the loading picture hints, this looks more beautiful, but feel more loss of performance, and sometimes also damaged the integrity of the site.

But after learning Jquery, I learned about Jquery.ajax, jquery.get, and so on, so that we could use WebService and. ashx files to interact with the server.
This jquery paging is in conjunction with the. ashx file.
Set up three. Ashx, respectively, for the PREVIEWHANDLER.ASHX,PAGEHANDLER.ASHX,NEXTHANDLER.ASHX, respectively, to deal with the current page, the next page, the previous page processing.
Pagehandler.ashx
Copy Code code as follows:

public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
Iqueryable<answer> Answer = xt. Answer.take (10);
StringBuilder sb = new StringBuilder ();
Sb. Append ("<table border= ' 1 ' width= ' 900px; ') ><tr><th> answer </th><th> Answer user name </th><th> Create time </th></tr> ");
foreach (Answer A in Answer)
{
Sb. Append ("<tr><td>" + a.answer_content + "</td><td>" + a.answer_username + "</td><td Onclick= ' Javascript:alert ("+" AA "+") ' > ' + a.answer_creatime + "</td></tr>");
}
Sb. Append ("</table>");
Context. Response.Write (SB);
}

Nexthandler.ashx
Copy Code code as follows:

public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
int rowcount = 10;
int current = Convert.ToInt32 (context. request.params["Index"]) + 1;
Iqueryable<answer> Answer = xt. Answer.skip (ROWCOUNT * (Current-1)). Take (ROWCOUNT);
StringBuilder sb = new StringBuilder ();
Sb. Append ("<table border= ' 1 ' width= ' 900px; ') ><tr><th> answer </th><th> Answer user name </th><th> Create time </th></tr> ");
foreach (Answer A in Answer)
{
Sb. Append ("<tr><td>" + a.answer_content + "</td><td>" + a.answer_username + "</td><td > "+ a.answer_creatime + </td></tr>");
}
Sb. Append ("</table>");
Context. Response.Write (SB);
}

Previewhandler.ashx
Copy Code code as follows:

public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
int rowcount = 10;
int current = Convert.ToInt32 (context. request.params["Index"])-1;
Iqueryable<answer> Answer = xt. Answer.skip (ROWCOUNT * (Current-1)). Take (ROWCOUNT);
StringBuilder sb = new StringBuilder ();
Sb. Append ("<table border= ' 1 ' width= ' 900px; ') ><tr><th> answer </th><th> Answer user name </th><th> Create time </th></tr> ");
foreach (Answer A in Answer)
{
Sb. Append ("<tr><td>" + a.answer_content + "</td><td>" + a.answer_username + "</td><td > "+ a.answer_creatime + </td></tr>");
}
Sb. Append ("</table>");
Context. Response.Write (SB);
}

Three files in fact the code is mostly similar, and then through the HTML or ASPX file to invoke, with Jquery.get ()
Copy Code code as follows:

<div id= "Lab" >
<input type= "button" onclick= "Init ();" value= "Initialization data"/>
<div id= "Content" style= "width:100%" >
</div>
<div id= "Pagepanel" >
<div style= "color:red" id= "PageInfo" ></div>
<a href= "#" onclick= "Preview ();" > Prev </a>
<a href= "#" onclick= "Next ()" > next page </a>
</div>
<!--store current page number-->
<input type= "hidden" class= "Currindex"/>
</div>
var init=function () {
$.get ("Pagehandler.ashx", function (data) {
document.getElementById (' content '). Innerhtml=data;
$ ('. Currindex '). attr (' value ', ' 1 ');
document.getElementById ("PageInfo"). Innerhtml= "Current 1th page";
});
}
var preview=function () {
var current=$ ('. Currindex '). attr (' value ');
var pre=number (current)-1;
$.get ("Previewhandler.ashx", {index:current},function (data) {
document.getElementById (' content '). Innerhtml=data;
$ ('. Currindex '). attr (' value ', pre);
document.getElementById ("PageInfo"). Innerhtml= "Current First" +pre+ "page";
});
}
var next=function () {
var current=$ ('. Currindex '). attr (' value ');
var next=number (current) +1;
$.get ("Nexthandler.ashx", {index:current},function (data) {
document.getElementById (' content '). Innerhtml=data;
$ ('. Currindex '). attr (' value ', next);
document.getElementById ("PageInfo"). Innerhtml= "Current First" +next+ "page";
});
}

To invoke the data generated by the. ashx file, click on the next page to overwrite the contents of the Nexthandler.ashx file Pagehandler.ashx file.
The result is as shown in figure:

The problem to be solved is to edit these lines, and I added a <tr onclick= ' del () in the. ashx file. ></tr>
And in the. aspx file also wrote Del method, but will error, object expected error, this error, should be unable to find Del method, their generation time, do not understand, has not been resolved,
Who can solve can tell me ...
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.