divfilup.InnerHtml//div后台这样取调试能看到值,可是就是不显示出来,为什么。
我点击按钮 function upFile(ob) {
var file = document.getElementById(ob);
var newName = "FileName"; //设置文件保存的名字
var form = document.createElement('form');
document.body.appendChild(form);
form.encoding = "multipart/form-data";
form.method = "post";
form.action = "Default10.aspx?nm=" + newName;
form.target = "hidden_frame";
var pos = file.nextSibling; //记住file在旧表单中的的位置
form.appendChild(file);
form.submit();
pos.parentNode.insertBefore(file, pos);
document.body.removeChild(form);
}异步又调用了本页面,在Page_Load里面判断
if (HttpContext.Current.Request.QueryString["nm"] != null)就给divfilup.InnerHtml一个值,可是怎么也不显示,调试是能看到值的,为什么呢,怎么解决
我点击按钮 function upFile(ob) {
var file = document.getElementById(ob);
var newName = "FileName"; //设置文件保存的名字
var form = document.createElement('form');
document.body.appendChild(form);
form.encoding = "multipart/form-data";
form.method = "post";
form.action = "Default10.aspx?nm=" + newName;
form.target = "hidden_frame";
var pos = file.nextSibling; //记住file在旧表单中的的位置
form.appendChild(file);
form.submit();
pos.parentNode.insertBefore(file, pos);
document.body.removeChild(form);
}异步又调用了本页面,在Page_Load里面判断
if (HttpContext.Current.Request.QueryString["nm"] != null)就给divfilup.InnerHtml一个值,可是怎么也不显示,调试是能看到值的,为什么呢,怎么解决
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function upFile(ob) {
var file = document.getElementById(ob);
var newName = "FileName"; //设置文件保存的名字
var form = document.createElement('form');
document.body.appendChild(form);
form.encoding = "multipart/form-data";
form.method = "post";
form.action = "Default10.aspx?nm=" + newName;
form.target = "hidden_frame";
var pos = file.nextSibling; //记住file在旧表单中的的位置
form.appendChild(file);
form.submit();
pos.parentNode.insertBefore(file, pos);
document.body.removeChild(form);
}
function ajax_call(data){
document.getElementById("divfilup").innerHTML=document.getElementById("divfilup").innerHTML+data;
alert(document.getElementById("divfilup").innerHTML);
}function aaa(val)
{
var fullFileName= new String(val.value.substring(val.value.lastIndexOf('\\') + 1));
var fileName = fullFileName.substring(0, fullFileName.lastIndexOf('.'));
document.getElementById('txtboxname').value=fileName;
document.getElementById('FileUpload1').value=val;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a>上传附件</a>
<table style="color:Black;">
<tr>
<td align="right">选择文件:</td>
<td>
<iframe name='hidden_frame' id="hidden_frame" style='width: 150px; height: 50px; display: none;'></iframe>
<input type="file" id="hidFilePath" name="updata" onchange="aaa(this)" />
</td>
</tr>
<tr>
<td align="right">名称:</td>
<td><asp:TextBox ID="txtboxname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right">描述:</td>
<td><asp:TextBox ID="txtcontent" TextMode="MultiLine" Width="300" Height="50" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td> <input id="upBtn" type="button" value="保存" onclick="upFile('hidFilePath');" /></td>
</tr>
</table>
<div id="divfilup" runat="server"></div>
</form>
</body>
</html>
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class test_Default10 : System.Web.UI.Page
{
string strConnection;
SqlConnection myConn;
protected void Page_Load(object sender, EventArgs e)
{
string str = "";
strConnection = ConfigurationSettings.AppSettings["gt"];
myConn = new SqlConnection(strConnection);
if (HttpContext.Current.Request.QueryString["nm"] != null)
{
string names = "";
string mz = HttpContext.Current.Request.QueryString["nm"].ToString();
Random ra = new Random();
int intra = ra.Next(0, 9000);
string filera = Convert.ToString(intra + 1000) + DateTime.Now.Millisecond.ToString(); //重新生成新的文件名
string NewFileName = System.DateTime.Now.ToString("yyyymmddhhhmmss") + System.DateTime.Now.DayOfYear.ToString() + mz.Length.ToString() + filera;
string uperr = "";
HttpFileCollection files = HttpContext.Current.Request.Files;
if (files.Count > 0)
{ uperr = upSingleFile(files[0], NewFileName);
SqlCommand cmd2 = new SqlCommand("select files_ls from Upload_file where id='" + uperr + "'", myConn);
myConn.Open();
SqlDataReader red = cmd2.ExecuteReader();
if (red.Read())
{
names = red["files_ls"].ToString();
}
myConn.Close();
}
else { uperr = "ok"; } str = "<table><tr><td>" + names + "</td><td><a>下载</a></td><td><a>删除</a></td></tr></table>"; //ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ajax_call('" + str + "');</script>");
divfilup.InnerHtml = str;
}
} //上传文件
private string upSingleFile(HttpPostedFile file, String theFileName)
{
string infos = "";
bool fileOK = false;
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(file.FileName);
if (fileName != "")
{
if (file.ContentLength >= 1024 * 1024 * 2)
{
infos = "上传文件太大,目前仅支持2M以内的文件上传!";
}
else
{
fileExtension = System.IO.Path.GetExtension(fileName).ToLower();
String[] allowedExtensions = { ".asf", ".asx", ".rm", ".ra", ".ram", ".swf", ".swi", ".flv", ".txt", ".doc", ".xls", ".docx", ".zip" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
break;
}
}
if (!fileOK)
{
infos = "不支持上传此类型文件!目前支持的文件格式有:asf|asx|rm|ra|ram|swf|swi|flv|txt|doc|xls|docx|zip";
}
else
{
string id = "";
string url = System.Web.HttpContext.Current.Server.MapPath("~/zw_file/" + theFileName + fileExtension);
SqlCommand com = new SqlCommand("insert into Upload_file(files_lj,files_name,files_conent,intime,files_ls)values('" + url + "','" + txtboxname.Text.Trim() + "','" + txtcontent.Text.Trim() + "',getdate(),'" + theFileName + fileExtension + "')", myConn);
myConn.Open();
com.ExecuteNonQuery();
myConn.Close(); SqlCommand cmds = new SqlCommand("select id from Upload_file order by intime desc", myConn);
myConn.Open();
SqlDataReader red = cmds.ExecuteReader();
if (red.Read())
{
id = red["id"].ToString();
}
myConn.Close();
file.SaveAs(url);
//infos =theFileName;
infos = id;
divfilup.InnerHtml = "<div>bbbbbb<div>";
}
}
}
else
{
infos = "没有读取到文件!";
}
return infos;
}
}
document.getElementById("divfilup").innerHTML=document.getElementById("divfilup").innerHTML+data;
alert(document.getElementById("divfilup").innerHTML);
}
我这里在将值给div我弹出都能看到值的,就是div显示不出来,不知道为什么