Solved

How to add newest DIVs at the top of the page

Posted on 2013-11-18
2
305 Views
Last Modified: 2013-11-18
I started to create a service to attempt to replicate the same functionality of Facebook posts and that is to have the newest comments on top.  My concern is that the newest posts to the page are being listed on the bottom.  How do I reverse that and add the newest posts to the top?  Thanks!

Here is what I have so far.  In the service page, here is what I have:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;

namespace NorthWindInfiniteScroll
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Test" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Test.svc or Test.svc.cs at the Solution Explorer and start debugging.
    [ServiceContract]
    public class Test
    {
        [OperationContract]
        [WebInvoke(Method= "POST",
            BodyStyle=WebMessageBodyStyle.Wrapped,
            ResponseFormat= WebMessageFormat.Json)]
        public string MyFunction(string Count)
        {
            

            return "The Count you passed in is: " + Count.ToString() + " " + DateControl().ToString() +  Control();
        }

        public DateTime DateControl()
        {

            DateTime datetime;

            datetime = DateTime.Now;

            return datetime;
        }

        public string Control()
        {
            string hello;

            LiteralControl literalcontrol = new LiteralControl();

            ImageButton imagebutton = new ImageButton();

            literalcontrol.Text = "<div><h1><b>hello world</b></h1></div>" + "<img id='Image1' src='Images/loading.gif'/>";
            

            hello = literalcontrol.Text;

            return hello;
        }
    }
}

Open in new window


And in the web page calling the service page, this is what I have:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallWCF.aspx.cs" Inherits="NorthWindInfiniteScroll.CallWCF" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Call WCF</title>
    <script src="Scripts/jquery-1.8.2.js" type="text/javascript"></script>
    <script type="text/javascript">

        var counter = 0;
        function CallMyService() {

            counter++;

            $.ajax({
                type: "POST",
                url: "Test.svc/MyFunction",
                data: '{"Count": "' + counter + '"}',
                contentType: "application/json",
                success: ServiceSucceeded,
                error: ServiceFailed
            });
        }

        function ServiceFailed(result) {

            Log('Service call failed: ' + result.status + ' ' + result.statusText);
        }

        function ServiceSucceeded(result)
        {
            resultObject = result.MyFunctionResult;
            Log("Success: " + resultObject);
        }

        function Log(msg) {
            $("#logdiv").append(msg + "<br />");
        }
    </script>
</head>
<body>
    <input id="Button1" type="button" value="Execute" onclick="CallMyService();" />
    <div id="logdiv">
    
    </div>    
</body>
</html>

Open in new window

0
Comment
Question by:VBBRett
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
Instead of:
$("#logdiv").append(msg + "<br />");

Open in new window

Try:
$("#logdiv").prepend(msg + "<br />");

Open in new window

0
 

Author Comment

by:VBBRett
Comment Utility
AWESOME!  Simple and it works!  Thank you very much!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now