JS在客户端,asp.net在服务器,如果要传值,只有提交到服务器。

解决方案 »

  1.   

    asp.net中获得动态生成组件中的值
    //是不是这个id=file的value还是??
    "<input type=\"file\"  id=\"file\" name=\"file\" value=\"\">
      

  2.   

    没错,就是动态生成的那组file的value
      

  3.   

    在.aspx文件中除了动态生成的file以外,还有一些web控件
    这些web控件中的值比较好弄些,就是这些动态生成的不好处理
    本来想在一个aspx页面与aspx.cs页面间传值可是半天没捣鼓出来
    所以只能退而求其次传到第二个.aspx中去处理了
      

  4.   

    <script>
    var  num=0;
    var Filearr=[]
    function ClickCreate()
    {
     var newRow =document.all.Table1.insertRow();
    var newCell = newRow.insertCell();
    newCell.innerHTML="<input type=\"file\"  id=\"file\" name=\"file\" value=\"\"> &nbsp;&nbsp;<INPUT type=\"button\" onclick=\"ClickDelete("+newRow.rowIndex+")\" name=\"delete"+newRow.rowIndex+"\" value=\"删除\"> <br>";   
     num++;
     }
      function ClickDelete(i)
     {
     var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;
     Table1.deleteRow(currRowIndex);
    }
    function f1()
    {var obj=document.getElementsByName("file");
    for(var i=0;i<obj.length;i++)
      {
      Filearr[i]=obj[i].value;
      }
      window.showModalDialog ('a.html', Filearr, 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') ;
    }
    </script>
    <form name=Form1>
    <input type=button value=显示 onclick=f1() ID=Button2>
    <input type=button value=增加 onclick=ClickCreate() ID=Button1>
    <table id=Table1>
    <tr><td></td></tr>
    </table>
    </form>
    /////////////////
    a.htm
    <SCRIPT>
    var oMyObject =[];
     oMyObject=window.dialogArguments;
    //var sFirstName = oMyObject.firstName;
    //var sLastName = oMyObject.lastName;
    </SCRIPT>
    <title>Untitled</title>
    </head>
    <BODY STYLE="font-family: arial; font-size: 14pt; color: Snow; 
    background-color: RosyBrown;">
    <SPAN STYLE="color:00ff7f">
    <SCRIPT></SCRIPT>
    </SPAN>
    <BR><SPAN STYLE="color:00ff7f">
    <script>
    for(i=0;i<oMyObject.length;i++)
    document.write(oMyObject[i]);
    document.write("<br>");
    </script></SPAN>
    </BODY>
    </HTML>
      

  5.   

    呵呵,解决了
    其实我就是一时马虎,忘了给form添加属性enctype="multipart/form-data"所以老是的不到aspx页面上动态产生的控件的值
     private void SaveImages()
        {
          ///遍历File表单元素
          HttpFileCollection files  = HttpContext.Current.Request.Files;      ///状态信息
          System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
          strMsg.Append("上传的文件分别是:<hr color=red>");
            for(int iFile = 0; iFile < files.Count; iFile++)
            {
              ///检查文件扩展名字
              HttpPostedFile postedFile = files[iFile];
              string fileName, fileExtension;
              fileName = System.IO.Path.GetFileName(postedFile.FileName);
              if (fileName != "")
              {
                fileExtension = System.IO.Path.GetExtension(fileName);
                strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString()+ "<br>");
                strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
                strMsg.Append("上传文件的文件名:" + fileName + "<br>");
                strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
                ///可根据扩展名字的不同保存到不同的文件夹
                ///注意:可能要修改你的文件夹的匿名写入权限。
                postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("file/") + fileName);
              }       
            }
        }