1

I want to test this code found here. It allows me to auto-load content from server as the user scrolls down the scroll down.

I am having difficulties trying to convert code to C#/ASP.NET. Primarily, I want this code to be translated to C#/ASP.NET:

package com.vraa.demo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InfinitContentServlet extends HttpServlet {
    private static Integer counter = 1;

    protected void processRequest(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
            String resp = "";
            for (int i = 1; i <= 10; i++) {
                resp += "<p><span>"
                        + counter++
                        + "</span> This is the dynamic content served freshly from server</p>";
            }
            out.write(resp);
        } finally {
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
}

In addition, I would like to know if I have to make any changes to this JavaScript code:

<script type="text/javascript">
        $(document).ready(function(){
            $contentLoadTriggered = false;
            $("#content-box").scroll(function(){
                if($("#content-box").scrollTop() >= ($("#content-wrapper").height() - $("#content-box").height()) && $contentLoadTriggered == false)
                {
                    $contentLoadTriggered = true;
                    $.get("infinitContentServlet", function(data){
                        $("#content-wrapper").append(data);
                        $contentLoadTriggered = false;
                    });
                }

            });
        });
    </script>
p.campbell
  • 98,673
  • 67
  • 256
  • 322
Eyad
  • 13,440
  • 6
  • 26
  • 43
  • 2
    So, how far did you get in your conversion attempt? – jball Nov 11 '10 at 22:54
  • not to far at all. Basically I don’t know the C# equivalent of the most of the code: the only thing I know is the for loop, try/finally, and the basic class/methods headers. Otherwise, everything is unknown. – Eyad Nov 11 '10 at 23:24
  • If you want to auto (defer) loading of content until scrolling in asp.net check http://stackoverflow.com/questions/4690174/deferred-loading-of-page-content-using-javascript-or-jquery and http://stackoverflow.com/questions/3283669/loading-content-with-ajax-while-scrolling – rabs Nov 14 '11 at 08:03

1 Answers1

1

similar concept I think.. (as a handler .ashx)

using System;
using System.Web;

public class InfinitContentHandler : IHttpHandler {
    private static Int32 counter = 1;

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";        

        for (int i = 1; i <= 10; i++) {
            context.Response.Write("<p><span>" + counter++ + "</span>");
            context.Response.Write("This is the dynamic content served freshly from server</p>");
        }

    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
Prescott
  • 7,312
  • 5
  • 49
  • 70