All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET常见错误提示_[Asp.Net教程]
javascript事件列表解说_JavaScript技术_编程技术
从HTML到XML_[XML教程]
PHP和AJAX打造高级RSS聚合器_php资料_编程技术
理解XML数据库_[XML教程]
SQL,Server,索引结构及其使用(一)_[SQL,Server教程]
获取总记录数、总页数的存储过程_[Asp.Net教程]
PHP函数:php中rename()函数的妙用_[PHP教程]
PHP实例:PHP实现定时生成HTML网站首页_[PHP教程]
Win2003,PHP5+MYSQL结合终极解决方案_php资料_编程技术
Reading number is top 10 pictures
Soong ching ling's former residence1
Born After 90 Beijing sports university campus flower photos1
这张图有两句话,你看出来了吗?
BingBingFan apple dew point photo gallery2
Earthquake hedge common sense
含苞欲放的素颜美少女2
The real super beauty3
初五接财神啦!五路财神齐来到
中国的阶级现状
色狗系列
Download software ranking
Tram sex maniac 2 (H) rar bag6
Boxer's Top ten classic battle5
JSP+Ajax Web development typical examples
Boxer's Top ten classic battle10
Sora aoi, the maid, students' uniforms
Boxer's Top ten classic battle8
Boxer's Top ten classic battle4
Sora aoi, the nurse, uniform ,nursing assistant
WebService在.NET中的实战应用教学视频 → 第1集
ASP.NET.2.0.XML.高级编程(第3版)
delv published in(发表于) 2014/1/27 6:49:39 Edit(编辑)
Javascript与asp.net,实现Ajax多文件无刷新上传_[Asp.Net教程]

Javascript与asp.net,实现Ajax多文件无刷新上传_[Asp.Net教程]

Javascript与asp.net 实现Ajax多文件无刷新上传_[Asp.Net教程]























这几天在等着上班,闲来无事,就写了一个无刷新的上传功能,这个上传只是实现局部刷新,我已经把方法都整理好,可以随意添加多个上传控件,只要调用一个方法就可以了,为了便于阅读我没有把JS独立出来,以后真正用到项目上的时候再提出来,我在每个方法上面都写了注视,具体可以看代码部分,现在一直在用JQuery,它提供的方法太好用的,剩了很多事。
此方法主要是通过iFrame调用上传页的控件来实现的,具体请看下面的代码。










无刷新上传主要的HTML代码(upload.html):










AjaxUpload


















onclick="hideDiv('tipbox');">[关闭]



AjaxUpload - 多文件无刷新上传源代码 v1.0


作者:李华顺 http://huacn.cnblogs.com











onclick="uploadcreate(('#uploadbox'));">添加一个新上传控件 onclick="uploadshowpic((this));">图片显示关闭



















上传功能的页面代码(upload.aspx):





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Inherits="upload" %>









上传



















上传功能的服务端代码(upload.aspx.cs)





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;




public partial class upload : System.Web.UI.Page
{
string picPath = "";
string picServer = "/upload";
protected string itemID = "";
protected void Page_Load(object sender, EventArgs e)
{




if (Request.QueryString["id"] != null)
{
itemID = Request.QueryString["id"];
}

if (IsPostBack)
{
picPath = Server.MapPath("\\upload");
doUpload();
}
}




protected void doUpload()
{
try
{
HttpPostedFile file = file1.PostedFile;
string strNewPath = GetSaveFilePath() + GetExtension(file.FileName);
file.SaveAs(picPath+strNewPath);
string urlPath = picServer + strNewPath;
urlPath = urlPath.Replace("\\", "/");
WriteJs("parent.uploadsuccess('" + urlPath + "','" + itemID + "'); ");

}
catch (Exception ex)
{
WriteJs("parent.uploaderror();");
}
}




private string GetExtension(string fileName)
{
try
{
int startPos = fileName.LastIndexOf(".");
string ext = fileName.Substring(startPos, fileName.Length - startPos);
return ext;
}
catch (Exception ex)
{
WriteJs("parent.uploaderror('" + itemID + "');");
return string.Empty;
}
}




private string GetSaveFilePath()
{
try
{
DateTime dateTime = DateTime.Now;
string yearStr = dateTime.Year.ToString(); ;
string monthStr = dateTime.Month.ToString();
string dayStr = dateTime.Day.ToString();
string hourStr = dateTime.Hour.ToString();
string minuteStr = dateTime.Minute.ToString();
string dir = dateTime.ToString(@"\\yyyyMMdd");
if (!Directory.Exists(picPath + dir))
{
Directory.CreateDirectory(picPath + dir);
}
return dir + dateTime.ToString("\\\\yyyyMMddhhmmssffff");
}
catch (Exception ex)
{
WriteJs("parent.uploaderror();");
return string.Empty;
}
}




protected void WriteJs(string jsContent)
{
this.Page.RegisterStartupScript("writejs","");
}




}







基本上就是这些,重点请看第一部份的代码,主要是JS控件显示,还有一个重点是upload.aspx调用父级页面的方法这些实现。




Javascript无刷新上传演示地址:http://www.wathon.com/opensource/js/ajaxuploadv1/upload.html
源代码下载地址:http://www.wathon.com/opensource/js/ajaxuploadv1/ajaxupload_src.zip
无刷新上传在编辑框中的应用演示:http://www.cnblogs.com/Files/huacn/ajaxupload_example.zip




来源:huacn的cnblogs













































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.