using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// <summary> /// Summary description for Comment /// </summary> public class Comment { public string Content; public DateTime Time; } <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div id="divcommon"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <h4><%#(Container.DataItem as CommonClass).Common %> </h4> <b><%#(Container.DataItem as CommonClass).dtnow %></b> <hr /> </ItemTemplate> </asp:Repeater> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1"/> </Triggers> </asp:UpdatePanel> </div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" οnclick="Button1_Click" /> <br /> <mce:script language="javascript" type="text/javascript"><!-- Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( function(sender, e) { var upid = "<%=this.UpdatePanel1.ID %>"; var updatedpanel = e.get_panelsUpdated(); for (var i = 0; i < updatedpanel.length; i++) { if (updatedpanel[i].id == upid) { updatedpanel[i].id = upid + Math.floor(9999 * Math.random()); var divcreate = document.createElement("div"); divcreate.id = upid; $get("divcommon").appendChild(divcreate); return; } } } ); // --></mce:script> </div> </form> </body> </html> using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { private static List<CommonClass> commonclass=null; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { commonclass = new List<CommonClass>(); WebLoadData(); } } private void WebLoadData() { this.Repeater1.DataSource = commonclass; this.Repeater1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { CommonClass commonclass = new CommonClass(); commonclass.dtnow = DateTime.Now; commonclass.Common = this.TextBox1.Text.ToString().Trim(); this.Repeater1.DataSource = new CommonClass[] {commonclass }; this.Repeater1.DataBind(); } } 参考:ASP.NET AJAX深入浅出系列课程