asp.net实现文件上传带进度条(多种风格)
文件上传 带进度条 多种风格 非常漂亮!
部分代码:
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server" EnablePageMethods="true" />
<script type="text/javascript">
var intervalID = 0;
var progressBar;
var fileUpload;
var form;
// 进度条
function pageLoad(){
addHandler(get(’upload’), ’click’, onUploadClick);
progressBar = find(’progress’);
}
// 注册表单
function register(form, fileUpload){
this.form = form;
this.fileUpload = fileUpload;
}
//上传验证
function onUploadClick() {
var vaild = fileUpload.value.length > 0;
if(vaild){
get(’upload’).disabled = ’disabled’;
updateMessage(’info’, ’初始化上传...’);
//提交上传
form.submit();
// 隐藏frame
Sys.UI.DomElement.addCssClass(get(’uploadFrame’), ’hidden’);
// 0开始显示进度条
progressBar.set_percentage(0);
progressBar.show();
// 上传过程
intervalID = window.setInterval(function(){
PageMethods.GetUploadStatus(function(result){
if(result){
// 更新进度条为新值
progressBar.set_percentage(result.percentComplete);
//更新信息
updateMessage(’info’, result.message);
if(result == 100){
// 自动消失
window.clearInterval(intervalID);
}
}
});
}, 500);
}
else{
onComplete(’error’, ’您必需选择一个文件’);
}
}
function onComplete(type, msg){
// 自动消失
window.clearInterval(intervalID);
// 显示消息
updateMessage(type, msg);
// 隐藏进度条
progressBar.hide();
progressBar.set_percentage(0);
// 重新启用按钮
get(’upload’).disabled = ’’;
// 显示frame
Sys.UI.DomElement.removeCssClass(get(’uploadFrame’), ’hidden’);
}
function updateMessage(type, value){
var status = get(’status’);
status.innerHTML = value;
// 移除样式
status.className = ’’;
Sys.UI.DomElement.addCssClass(status, type);
}
</script>
相关文档:
Beyond File | New Company: from Cheesy Sample to Social Platform Scott Hanselman in Lagoon L on Monday at 11:30 AM The web has changed and there's a new way of thinking about your applications. You can't just write some HTML and CSS anymore and expect to be the next Twitter. Hear h ......
与ASP相比,ASP.NET在很多方面有了显著的改进,这些方面包括:性能、状态管理、可缩放性、配置、部署、安全性、输出缓存控制、网络场支持和XML Web services结构等。
如果您具有ASP 开发技能,则新的 ASP.NET 编程 ......
最近在看《asp.net通用模块及典型系统开发实例导航》,其中用到了MD5加密,代码如下: /// <summary>
/// 字符串加密函数
/// </summary>
/// <param name="strInput">输入被加密的字符串</param>
/// <returns>加密后的字符串</return ......
try
{
// 要提交表单的URI字符串。
string uriString = "http://localhost:1165/WebTest/MyLogin.aspx";
//// ......
Asp.Net 构架(Http Handler 介绍) - Part.2
引言
在 Part.1 Http请求处理流程 一文中,我们了解了Http请求的处理过程以及其它一些运作原理。我们知道Http管道中有两个可用接口,一个是IHttpHandler,一个是IHttpModule,但在Part.1中,我并没有详细讲述如何对它们进行编程,只是轻描淡写地一笔带过。所谓学以致用,前面已 ......