Solved

How to add newest DIVs at the top of the page

Posted on 2013-11-18
2
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

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

Open in new window

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

Open in new window

0
 

Author Comment

by:VBBRett
ID: 39656364
AWESOME!  Simple and it works!  Thank you very much!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

690 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