问题描述
我看到这样一段代码父窗体page.aspx<html><body><scriptlanguage="C#"runat="server"></script><formid="Form1"method=postrunat="server"><asp:TextBoxID=txtNameRunat=server></asp:TextBox><inputtype=buttonvalue="弹出子窗口"onclick="Mywin=window.open('subpage.aspx');"></form></body></html>子窗体subpage.aspx<html><body><scriptlanguage="JavaScript">functionpopup(){window.opener.document.all["txtName"].value=document.all["txtSubName"].value;window.close()}</script><scriptlanguage="C#"runat="server"></script><formid="Form1"method=postrunat="server"><asp:TextBoxID=txtSubNameRunat=server></asp:TextBox><p><inputtype="button"value="传值并返回父窗口"name="button1"onclick="popup()"></p></form></body></html>这个方法只能传递一个参数.我现在将子窗体改成下面的样子<body><scriptlanguage="C#"runat="server"></script><formid="Form1"method="post"runat="server"><spanid="Info"runat="server"></span><asp:TextBoxID="txtSubName"runat="server"></asp:TextBox><p><inputtype="button"value="传值并返回父窗口"name="button1"onclick="popup()"></p><asp:TextBoxID="txtSubName1"runat="server"></asp:TextBox><p><inputtype="button"value="传值并返回父窗口"name="button2"onclick="popup()"></p></form></body></html><scripttype="text/javascript"language="JavaScript">functionpopup(fm){window.opener.document.all("txtName").value=fm;window.close();}</script>CS代码为fnames="<divid='fileList'runat='server'onclick='popup(""+Filelist[i].Name.ToString()+"")'>"+Filelist[i].Name+"</div>";//HyperLink1.Text+=Image1.ImageUrl.ToString()+fnames;//Label1.Text+=fnames.ToString();Info.InnerHtml+="<ImgID='Image1'src='"+fnamesImage+"'Visible='true'/>"+" "+fnames.ToString()+" "+fnamesTime.ToString()+"</br>";但这样一来我父窗体如果有多个TextBox,每次都只是最后一个得到了传递的数值.不知道有没有什么好的方法.能让父窗体的每一个button点击之后.其相对应的textbox都可以得到相对应的从子窗体获得得参数
解决方案
解决方案二:
<scripttype="text/javascript"language="JavaScript">functionpopup(fm){window.opener.document.all("txtName").value=fm;window.opener.document.all("txtName1").value="sdf";window.opener.document.all("txtName2").value="sdf";window.opener.document.all("txtName3").value="sdfdsf";window.close();}</script>