<%@ Register Assembly="AjaxFileUploadHelper" Namespace="Jeffz.Web" TagPrefix="jeffz" %> //... <asp:ScriptManager ID="ScriptManager1" runat="server" /> <jeffz:AjaxFileUploadHelper runat="server" ID="AjaxFileUploadHelper1" /> //...
<%= DateTime.Now %> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <%= DateTime.Now %><br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" /><br /> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </ContentTemplate> </asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e) { if (this.FileUpload1.PostedFile != null) { this.Label1.Text = this.FileUpload1.PostedFile.ContentLength + " bytes"; } else { this.Label1.Text = ""; } }
protected void Button1_Click(object sender, EventArgs e) { this.Response.Redirect("AnotherPage.aspx", true); }
<system.web> <!-- other configurations --> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, ..."/> </httpModules> <!-- other configurations --> </system.web> <!-- for IIS 7 --> <system.webServer> <!-- other configurations --> <modules> <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, ..."/> </modules> <!-- other configurations --> </system.webServer>
public class ScriptModule : IHttpModule { protected virtual void Init(HttpApplication context) { context.PreSendRequestHeaders += new EventHandler(PreSendRequestHeadersHandler); // ... } private void PreSendRequestHeadersHandler(object sender, EventArgs args) { HttpApplication application = (HttpApplication)sender; HttpResponse response = application.Response; if (response.StatusCode == 302) { if (PageRequestManager.IsAsyncPostBackRequest(application.Request.Headers)) { string redirectLocation = response.RedirectLocation; List<HttpCookie> cookies = new List<HttpCookie>(response.Cookies.Count); for (int i = 0; i < response.Cookies.Count; i++) { cookies.Add(response.Cookies[i]); } response.ClearContent(); response.ClearHeaders(); for (int i = 0; i < cookies.Count; i++) { response.AppendCookie(cookies[i]); } response.Cache.SetCacheability(HttpCacheability.NoCache); response.ContentType = "text/plain"; PageRequestManager.EncodeString(response.Output, "pageRedirect", String.Empty, redirectLocation); } else if //... } } }
function Sys$WebForms$PageRequestManager$_onFormSubmitCompleted(sender, eventArgs) { // ... for (var i = 0; i < delta.length; i++) { var deltaNode = delta[i]; switch (deltaNode.type) { case "updatePanel": Array.add(updatePanelNodes, deltaNode); break; // ... case "pageRedirect": window.location.href = deltaNode.content; return; //... } } // ... }
public class AjaxFileUploadModule : IHttpModule { public void Init(HttpApplication context) { context.PreSendRequestHeaders += new EventHandler(PreSendRequestHeadersHandler); } private void PreSendRequestHeadersHandler(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpResponse response = application.Response; if (response.StatusCode == 302 && AjaxFileUploadUtility.IsInIFrameAsyncPostBack(application.Request.Params)) { string redirectLocation = response.RedirectLocation; List<HttpCookie> cookies = new List<HttpCookie>(response.Cookies.Count); for (int i = 0; i < response.Cookies.Count; i++) { cookies.Add(response.Cookies[i]); } response.ClearContent(); response.ClearHeaders(); for (int i = 0; i < cookies.Count; i++) { response.AppendCookie(cookies[i]); } response.Cache.SetCacheability(HttpCacheability.NoCache); response.ContentType = "text/plain"; AjaxFileUploadUtility.WriteScriptBlock(response, true); StringBuilder sb = new StringBuilder(); TextWriter writer = new StringWriter(sb); AjaxFileUploadUtility.EncodeString(writer, "pageRedirect", String.Empty, redirectLocation); response.Write(sb.Replace("*/", "*//*").ToString()); AjaxFileUploadUtility.WriteScriptBlock(response, false); response.End(); } } public void Dispose() {} }
<script type='text/javascript' language='javascript'>window.__f__=function() {/*16|pageRedirect||/AnotherPage.aspx|*/}</script>
本文出自 “赵��” 博客,转载请与作者联系!