Share the source code of a callback-based non-refresh upload progress bar control. The HttpMoudule used in this control is based on a sample of Baoyu's upload progress bar. It is encapsulated into a control for easy use. No code is required, just set up web.config, add a reference to HttpModule, and drag the control to the page. The file saving operation in the page is exactly the same as the traditional asp.net file upload. You can set the attribute to jump to other pages when an error occurs during the upload process or when the upload is successful. Compatible with IE, Firefox, Opera. It has not been tested in other environments, but because it is based on Asp.Net2.0 callback, other browsers should support it as long as it supports xmlhttp or iframe.
For online demonstration, please visit: http://teddy.cn/test
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits=" _Default" %>
2
3<%@ Register Assembly="Framework.Web" Namespace="Ilungasoft.Framework.Web.UI.WebControls"
4 TagPrefix="cc1" %>
5<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
6<html xmlns=" http://www.w3.org/1999/xhtml ">
7<head id="Head1" runat="server">
8 <title>Untitled Page</title>
9</head>
10<body>
11 <form id="form1" runat="server">
12 <div>
13 <asp:FileUpload ID="FileUpload1" runat="server" /><br />
14 <br />
15 <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" /><br />
16 <br />
17 <cc1:UploadProgressBar ID="UploadProgressBar1" runat="server" UploadButtonName="Button1" UploadErrorRedirectUrl="UploadError.aspx">
18 </cc1:UploadProgressBar>
19 <br />
20 <br />
21 </div>
22 </form>
23</body>
24</html>
Default.aspx.cs
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10
11public partial class _Default : System.Web.UI.Page
12{
13 protected void Page_Load(object sender, EventArgs e)
14 {
15
16}
17 protected void Button1_Click(object sender, EventArgs e)
18 {
19 FileUpload1.SaveAs(Server.MapPath("test.tmp"));
20}
twenty one}
Don’t you feel that there is any more code than before using this control? ;-)
Enjoy!