日期:2014-05-18  浏览次数:20413 次

javascript动态生成的控件为何在刷新后就消失了
javascript动态生成的控件为何在刷新后就消失了
请高手解答
谢谢

------解决方案--------------------
javascript只是操纵客户端,刷新后,等价于从服务端重新下载页面,帮会消失。
------解决方案--------------------
我原来写过一个贴子,你看一下吧
------解决方案--------------------
无论是javascript或者服务器端动态加载的控件,刷新后,都会消失。
------解决方案--------------------
javascript是客户端脚本,写在客户端的,
页面也是从服务器下载到本地运行,
一刷新,然后又从服务器读取,下载到本地,
所以出现这样的情况
------解决方案--------------------
因为动态生成的是在客户端,而刷新是提交到服务器端了。所以你的控件消失了。
------解决方案--------------------
后台获取用 Request获取表单信息。
#region 上传新附件

ArrayList al =new ArrayList();
for(int i = 0;i <Request.Form.Count;i++)
{
if(Request.Form.Keys[i].ToString().Length> 4)
{

if(Request.Form.Keys[i].ToString().Substring(0,4)== "fjsm ")
{

al.Add(Request.Form[i].ToString());

}
}
}

/// '遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;

/// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
string fileName,fileSearchName, fileExtension,strFJXH1,strFJBT1,strDirectory,strSearchDirectory;
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
/// '检查文件扩展名字
HttpPostedFile postedFile = files[iFile];

fileName = System.IO.Path.GetFileName(postedFile.FileName);
fileSearchName=fileName;

fileExtension = System.IO.Path.GetExtension(fileName);
strFJXH1 =(new AppDataCMP.DocumentManageCMP()).GetNewID( "OA_DA_FJ ", "FJXH ").ToString();
fileName= "gxb_ "+SystemManage.SystemUserManage.GetUserID(Session).ToString()+ "_ "+strFJXH1+fileExtension;
fileSearchName=fileSearchName.Replace(fileExtension, " ")+ "[ "+strFJXH1+ "] "+fileExtension;
//生成目录
strDirectory=(new AppDataCMP.DocumentManageCMP()).GetDocumentAtthfilesUpLoadDirectory(System.Web.HttpContext.Current.Request.MapPath( "DocumentAtthfiles/ "));
strSearchDirectory=(new AppDataCMP.DocumentManageCMP()).GetDocumentSearchUpLoadDirectory(System.Configuration.ConfigurationSettings.AppSettings[ "FilePath "],this.txtFBFL.Text+@ "\ ");
//寻找附件标题
strFJBT1=al[iFile].ToString();



//增加到数据库
SortedList temp = new SortedList();

temp.Add( "FJXH ",strFJXH1);
temp.Add( "DAXH ",this.txtDAXH.Text);
temp.Add( "FJBT ",strFJBT1);
temp.Add( "CDLJ ", "documentatthfiles "+@ "/ "+strDirectory.Substring(strDirectory.Length-8,8)+@ "/ "+fileName);
//temp.Add( "CCGS ",null)
//temp.Add( "XJCX ",null);
AppDataCMP.DocumentManageCMP dm = new AppDataCMP.DocumentManageCMP();
dm.Open();
dm.AddNewDocumentAtthfiles(temp);
dm.Close();

//上传附件
postedFile.SaveAs(strDirectory +@ "\ "+ fileName);
postedFile.SaveAs(strSearchDirectory+@ "\ "+ fileSearchName);
}

}
catch(System.Exception Ex)
{
strStatus.Text = Ex.Message;

}

#endregion