选择文件后就上传文件,不用点击再"按钮"上传....
解决方案 »
- |zyciis| 老问题,如何重启网站,开始的修改WebConfig的办法不行,在服务器提示访问web.config被拒绝,PS:服务器不可以修改权限
- asp.net 弹出窗口问题 挑战性问题(死活就是不弹出来)
- 当Response.Redirect(),session会无效吗?
- 求助!!我想做网上书店的显示书籍列表!!实在是不会了!
- 库存管理怎么控制库存数量?求教
- 大分值提问了.. 网上购物系统
- 这个错误怎么处理????在线等.............
- ASP.NET2.0+SQL2000的问题!没入门, 别笑我!
- 如何保存从TreeView返回的参数值?
- 如何将数据库中“2002-01-01”格式的时间转变为“2002/01/01”
- asp.net URL重写的正则表达式怎么写?
- 分割区域
<CE:Uploader ID="Uploader1" runat="server" InsertText="Uploader控件"
MultipleFilesUpload="true">
<ValidateOption AllowedFileExtensions="*.jpg;*;gif;*.bmp;*.png" MaxSizeKB="2048" />
</CE:Uploader>
需要dll 邮件给我 [email protected]
运用<input type="file" run="server" id="Upfile" style="display:none" />
<input type="button" id="disFile" onclick="方法使Upfile点击显示对话框" />
比如
function FnDisFile()
{
document.getElementById("Upfile").click();//显示文件选择
var _fName=document.getElementById("Upfile").value;
你上传的按钮.click();
}在这里我们得认识一点,关于alert、comfirm、文件选择之类的,他们是模式窗口,可以将js线程暂停(姑且这么认为),当你点确定按钮后,线程释放继续执行。这个可以体会一下模式窗口
Inherits="Account_AttachmentUpload" %><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>上传审核资料</title>
<link rel="stylesheet" href="/css/style.css" type="text/css">
<style type="text/css">
.AStyle
{
color:Blue;
font-size:15px;
cursor:hand;
}
</style> <script language="javascript" type="text/javascript" src='<%=Page.ResolveUrl("~/JS/jquery.js")%>'>
</script></head>
<body class="body_bg">
<form id="form1" runat="server">
<table width="100%" border="6" cellpadding="6" cellspacing="6" align="center">
<tr bgcolor="#fefce3">
<td>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td bgcolor="#FFFFFF">
<table style="margin-top: 5px; margin-left: 5px; width: 100%;">
<tr>
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<img src="/images/dian_1.gif" border="0" align="absmiddle"><span style="color: #ff8200;
font-size: 13px; font-weight: bold">上传审核资料</span></td>
<td align="right" id="sure" onclick="window.close()">
<img src="/images/close.gif" border="0" align="absmiddle">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" height="1" background="/images/shd_22.gif">
</td>
</tr>
<tr>
<td height="32" width="30%" align="right">
请选择上传资料的类型:</td>
<td>
<asp:DropDownList ID="ddlCategory" runat="server" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr>
<td height="32" align="right">
自定义文件名:</td>
<td>
<asp:TextBox ID="txtName" runat="server" Width="260px"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" valign="top" style="padding-top: 6px">
请选择上传图片:</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" Width="99%" />
支持的文件格式:<span id="SupportFileTypes" style="color: Red"></span>
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="" Width="0"
Height="0" />
<span id="Notice" style="display: none; color: Red; width: 100%">正在上传中……</span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body><script type="text/javascript">
var FileUpload1 = document.getElementById("FileUpload1");
var form1 = document.getElementById("form1");
var Notice = document.getElementById("Notice");
var permitFileTypes = "jpg,jpeg,gif,png,giff,doc,pdf";
var support = document.getElementById("SupportFileTypes");
support.innerHTML = permitFileTypes.replace("|", " ");
FileUpload1.onchange = function() {
if (!PermitFileType(FileUpload1.value))
{
alert("只允许上传 " + permitFileTypes.replace("|", " ") + " 文件");
return;
}
var s = FileUpload1.value;
var img = new Image();
img.src = s;
if(img.fileSize>2048*1024){
alert("上传图片的最大限制为2M,请选择一个较小的文件上传");
return;
}
Notice.style.display = "inline";
document.getElementById("btnUpload").click();
};
function PermitFileType(filename)
{
var i = filename.lastIndexOf(".");
if (i == -1) return false;
var fileType = filename.substr(i + 1).toLowerCase();
if (permitFileTypes.indexOf(fileType) == -1)
return false;
return true;
}
</script></html>
后台:
protected void btnUpload_Click(object sender, EventArgs e)
{
string fname = string.Empty;
if (this.txtName.Text == "")
{
fname = FileUpload1.FileName.Replace(" ", "");
string[] fext = fname.Split('.');
fname = fext.Length > 5 ? fext[0].Substring(0, 5) : fext[0];
fname = fname + "." + fext[1];
}
else
{
fname = this.txtName.Text.Trim();
} Hashtable attach = new Hashtable();
attach["UserCode"] = this.SohodaiUserCode;
attach["CategoryID"] = this.ddlCategory.SelectedValue;
attach["Attachment"] = fname; //文件名称
attach["Location"] = CompUtility.UploadFile(this.SohodaiUserCode, "Attachment", this.FileUpload1); //数据库里存储地址是用户注册日期+用户名+类型+当前日期+文件名
attach["AddDate"] = DateTime.Now;
attach["ModifyDate"] = DateTime.Now;
attach["DeleteFlag"] = 0; #region 更新用户这一类的项目状态
Hashtable examineresult = new ExamineResultRule().GetExamineResultByCondition(this.SohodaiUserCode, this.ddlCategory.SelectedValue);
if (examineresult != null)
{
Hashtable htnew = new Hashtable();
htnew["ExamineState"] = 0;
examineResultRule.UpdateExamineResult(htnew, examineresult["ExamineResultID"].ToString());
}
#endregion try
{
userAttachment.InsertUserAttachment(attach);
}
catch (Exception ex)
{ throw ex;
}
Response.Write("<script defer>window.opener.document.all('ctl00_ContentPlaceHolder2_btnFresh').click();</script>");
}