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

解决方案 »

  1.   

    javascript只是操纵客户端,刷新后,等价于从服务端重新下载页面,帮会消失。
      

  2.   

    无论是javascript或者服务器端动态加载的控件,刷新后,都会消失。
      

  3.   

    javascript是客户端脚本,写在客户端的,
    页面也是从服务器下载到本地运行,
    一刷新,然后又从服务器读取,下载到本地,
    所以出现这样的情况
      

  4.   

    //增加控件
    function addClientControls()
    {
    var count_obj;
    var tr_obj;
    var td_obj;
    var file_obj;
    var form_obj;
    var count;
    var table_obj;
    var button_obj;
    var countview_obj;
    var str1;
    var str2;
    form_obj=document.getElementById("Form1");

    fj_obj=document.getElementById("td_fj");

    if(fj_obj.innertext=="无附件")
    {
    fj_obj.innertext="";
    }

    count_obj=document.getElementById("count_obj"); if (count_obj==null)
    {
    count_obj=document.createElement("input");
    count_obj.type="hidden";
    count_obj.id="count_obj";
    count_obj.value=1;

    form_obj.appendChild(count_obj);
    count=1;
    count_obj.value=1;
    }
    else
    {
    count_obj=document.getElementById("count_obj");
    count=Number(count_obj.value)+1;
    count_obj.value=count;
    }

    div_obj=document.createElement("div");
    div_obj.id="div_" + count;
    div_obj.align="center";

    fj_obj.appendChild(div_obj);

    str1="附件名称:<input type='file' name='fj"+count+"' size=55 class='input' id=fj"+count+">";
    str2="<br>附件标题:<input type='text' name='fjsm"+count+"' class='input' size=55 maxlength=100 id='fjsm"+count+"'>";
    str3="<input type='button' class='button' value='删除本条' onclick=javascript:delClientControls("+"\""+div_obj.id+"\""+"); id='button"+count+"' name='button"+count+"'>";       
    div_obj.innerHTML=str1+str2+str3;
    }//删除控件
    function delClientControls(id) 
    {
    var child;
    var parent;
    var count_obj; child=document.getElementById(id);
    count_obj=document.getElementById("count_obj");

    if(child==null)
    {
    alert("对象为空");
    }
    else
    {
    child.removeNode(true)
    count_obj.value=Number(count_obj.value)-1;
    if(count_obj.value=="0")
    {
    count_obj.removeNode(true);
    }

    }  parent=document.getElementById("td_fj");

    if(!parent.hasChildNodes)
    {
    parent.innerText="";

    }
    }
      

  5.   

    后台获取用 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
      

  6.   

    重新从服务上下载了网页文件.你生成的只是客户端而已.
    了解下web原理先.