aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtTest" runat="server" Text="tes"></asp:TextBox> <asp:Repeater ID="repTest" runat="server"> <ItemTemplate> <%#Eval("name") %> <%#Eval("value") %> </ItemTemplate> </asp:Repeater> <asp:FileUpload ID="fupTest" runat="server" /> <asp:Button runat="server" ID="btnTest" Text="upload" OnClick="btnUploadEventClick" /> </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; using Wuqi.Webdiyer; using System.Threading; namespace WebApplication4 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } public void BindData() { Random rand = new Random(); repTest.DataSource = new[] { new {name="aa",value=rand.Next()}, new {name="bb",value=rand.Next()}, new {name="cc",value=rand.Next()}, new {name="dd",value=rand.Next()}, new {name="dd",value=rand.Next()}, new {name="dd",value=rand.Next()}, }; repTest.DataBind(); } protected void btnUploadEventClick(object sender, EventArgs e) { string phyPath = Server.MapPath(""); fupTest.SaveAs(phyPath+"/test.txt"); TransmiteFile();// 有这个方法,导致对Repeater,和txtTest 的更新不起作用,注释后,可以对控件实现更新 txtTest.Text = "changed"; BindData(); } protected void TransmiteFile() { string phyPath = Server.MapPath(""); Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("Content-Disposition", "attachment;filename=z.zip"); Response.TransmitFile(phyPath + "/test.txt"); // Response.End(); } } }