Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to add newest DIVs at the top of the page

Posted on 2013-11-18
2
Medium Priority
?
312 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

604 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