Solved

How to add newest DIVs at the top of the page

Posted on 2013-11-18
2
307 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

785 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