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 ......
使用WebClient自动填写并提交ASP.NET页面表单
在.NET中通过程序填写和提交表单还是比较简单。比如,要提交一个如下图所示的登录表单:
填写和提交以上表单的代码如下:
&nb ......
try
{
// 要提交表单的URI字符串。
string uriString = "http://localhost:1165/WebTest/MyLogin.aspx";
//// ......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace ......
1.什么是cookie?
cookie 是一小段文本信息,伴随用户请求,在web服务器和浏览器之间传递。用户每次访问站点的时候,
web应用程序都可以读取cookie包含的信息。
假设在用户请求您的网站的某个页面时,您的应用程序不仅是返回请求的页面。同时也返回一个包含日期
和时间的cookie。用户的浏览器在获得页面的同时也获得 ......