共享一个基于Callback的无刷新上传进度条控件的源码。本控件使用的HttpMoudule基于宝玉的一个上传进度条的sample,这里封装为一个控件,方便使用。无需任何代码,只需设置web.config,添加HttpModule的引用,再将控件拖到页面就行。页面中的文件保存操作和传统的asp.net文件上传完全一样。可以设置属性上传过程中出错或上传成功时跳转到其它页面。兼容IE,Firefox,Opera。其它环境没测试,不过因为是基于Asp.Net2.0的callback,其他浏览器只要支持xmlhttp或iframe就应该支持。
在线演示请访问: http://teddy.cn/test
源码及示例下载
(在本机运行示例注意将程序所在目录设为对web帐号可写,否则上传文件是会权限不足报错)
下面简单列举一下示例中的web.config和Default.aspx和Default.aspx.cs。
web.config
Default.aspx (注意Line 17必须设置控件的UploadButtonName为页面中出发上传事件的按钮运行时生成的input标签的name属性。对于包含模版页的情况,name可能形如:ctl00$ContentPlaceHolder1$Button1)
Default.aspx.cs
是不是没感觉到和使用该控件之前相比多了任何代码呢?;-)
Enjoy!
在线演示请访问: http://teddy.cn/test
源码及示例下载
(在本机运行示例注意将程序所在目录设为对web帐号可写,否则上传文件是会权限不足报错)
下面简单列举一下示例中的web.config和Default.aspx和Default.aspx.cs。
web.config
1
<?
xml version="1.0"
?>
2
<
configuration
>
3
<
appSettings
/>
4
<
connectionStrings
/>
5
<
system
.web
>
6
<
compilation
debug
="true"
/>
7
<
authentication
mode
="Windows"
/>
8
<
httpModules
>
9
<
add
name
="HttpUploadModule"
type
="Ilungasoft.Framework.Web.Modules.UploadProgressModule, Framework.Web"
/>
10
</
httpModules
>
11
<
httpRuntime
maxRequestLength
="1000000"
executionTimeout
="300"
/>
12
</
system.web
>
13
</
configuration
>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
Default.aspx (注意Line 17必须设置控件的UploadButtonName为页面中出发上传事件的按钮运行时生成的input标签的name属性。对于包含模版页的情况,name可能形如:ctl00$ContentPlaceHolder1$Button1)
1
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
%>
2![](/Images/OutliningIndicators/None.gif)
3![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
<%
@ 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
>
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
4
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)
20
![](/Images/OutliningIndicators/None.gif)
21
![](/Images/OutliningIndicators/None.gif)
22
![](/Images/OutliningIndicators/None.gif)
23
![](/Images/OutliningIndicators/None.gif)
24
![](/Images/OutliningIndicators/None.gif)
Default.aspx.cs
1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Web;
5
using
System.Web.Security;
6
using
System.Web.UI;
7
using
System.Web.UI.WebControls;
8
using
System.Web.UI.WebControls.WebParts;
9
using
System.Web.UI.HtmlControls;
10![](/Images/OutliningIndicators/None.gif)
11
public
partial
class
_Default : System.Web.UI.Page
12![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
13
protected void Page_Load(object sender, EventArgs e)
14![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
15![](/Images/OutliningIndicators/InBlock.gif)
16
}
17
protected void Button1_Click(object sender, EventArgs e)
18![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
19
FileUpload1.SaveAs(Server.MapPath("test.tmp"));
20
}
21
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
21
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
是不是没感觉到和使用该控件之前相比多了任何代码呢?;-)
Enjoy!