日期:2014-05-20  浏览次数:21054 次

.net下的ajax问题,请教高手
如何实现像t.sina.com.cn首页中间那里的无刷新自动下滑功能,.net下如何实现?请教高手,最好能有源码,谢谢!

------解决方案--------------------
装个firebug,到新浪上看一下...
------解决方案--------------------
ajax+jquery
------解决方案--------------------
我告诉你思路吧,你在前台放个Panel,然后通过ajax判断数据是否有新的,有新的话就动态在后台给panel加div
------解决方案--------------------
C# code
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="下滑.aspx.cs" Inherits="下滑" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title> </title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  <div>
    <asp:Button ID="btnStart" runat="server" Text="启动" onclick="btnStart_Click" />
    <asp:Button ID="btnEnd" runat="server" Text="停止" onclick="btnEnd_Click" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
        <asp:Timer runat="server" ID="timer" ontick="timer_Tick">
        </asp:Timer>
        <asp:Literal ID="lit_Div" runat="server"> </asp:Literal>
        <asp:HiddenField ID="hf_i" runat="server" />
      </ContentTemplate>
      <Triggers>
        <asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
      </Triggers>
    </asp:UpdatePanel>
  </div>
  </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 下滑 : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    timer.Interval = 1000;
  }
  protected void timer_Tick(object sender, EventArgs e)
  {
    this.lit_Div.Text += string.Format(" <div style='border:1px #ff00ff solid;'> <a href='#'>链接 </a> </div>");
  }
  protected void btnStart_Click(object sender, EventArgs e)
  {
    timer.Interval = 1000;
    timer.Tick+=new EventHandler <EventArgs>(timer_Tick);
  }
  protected void btnEnd_Click(object sender, EventArgs e)
  {
    timer.Interval = 30000;
    timer.Tick -= new EventHandler <EventArgs>(timer_Tick);
  }
}


------解决方案--------------------
我本来是用这个方法可以实现的,后来我仔细看了下那个网站,其实它是个假象,它的原理是把所有的数据读出来放到层里面,然后通过js和CSS来控制显示和隐藏的。哎。。。无语了