您的位置:首页 > 其它

在套用母版页的页面中应用input file上传图片

2012-05-13 03:20 267 查看
在套用母版页的页面中应用input type="file" 上传图片
若是Request.Files 始终是0,添加以下信息:

(1)在套用页面Page_Load中添加 Form.Enctype = "multipart/form-data";不要在母版页中加

(2)确保input type="file"包含 name属性,不然也取不到上传的文件。

另附一段JS动态添加上传标签的JS代码:

function AddFileControl() {
var uploads = document.getElementsByName("upFile");
if (uploads.length >= 10) {
alert("最多可以添加10个附件");
return false;
}
var innerDiv = document.createElement("div");
document.getElementById("dv1").appendChild(innerDiv);
var fileControl = document.createElement("input");
fileControl.name = "upFile";
fileControl.type = "file";
innerDiv.appendChild(fileControl);
var btnControl = document.createElement("input");
btnControl.name = "btnDelete";
btnControl.type = "button";
btnControl.setAttribute("value", "删除");
btnControl.onclick = function () { DeleteFileControl(this.parentNode) };
innerDiv.appendChild(btnControl);
}

function DeleteFileControl(obj) {
document.getElementById("dv1").removeChild(obj);
}


上传标签统一添加到页面名为:dv1的DIV标签中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: