如何通过C#来实现Web窗体互动? 我想做一个Web页面(父窗口),其中包含有一个上传文件的链接,我想在单击该链接后打开一个新窗口(子窗口),来实现文件的上传,文件上传完毕后,将文件的上传路径写入父窗口的一个Label中,请都如何实现。哪有这种窗体互动的详细资料啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在html 中写类似window.open 的语句,你到网上查一下,打开新窗体,这样的文章很多的。你把文件上传的代码写在一个页面中,父页面与子页面通过session传值即可, 用Session不可能在传完后就把文件的上传路径写入父窗口的一个Label中啊 你用window.open 打开这个窗口。 然后openner对象就是父窗口了。然后使用javascritp改变其中的一个span(就是你说的那个label)就可以。 弹出窗口传值回主窗口(2005下测试成功)1:Main.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Temp_Pop_Main" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"> <div> <asp:Button OnClientClick="OpenWin()" ID="Button1" runat="server" Text="Button" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div> </form></body></html><script>function OpenWin(){ var ReturnValue=new Array(); ReturnValue[0]=document.all.TextBox1.value; window.showModalDialog("Pop.aspx",ReturnValue,"dialogHide:yes;dialogWidth:300px;dialogHeight:300px"); document.all.TextBox1.value =ReturnValue[0]; } </script>2:Pop.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pop.aspx.cs" Inherits="Temp_Pop_Pop" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body onload="SetData()" onunload="GetData()"> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button OnClientClick="GetData();window.close();" ID="Button1" runat="server" Text="Button" /></div> </form></body></html><script>var ResponseValue=window.dialogArguments;function SetData(){ document.all.TextBox1.value=ResponseValue[0];}function GetData() { ResponseValue[0]=document.all.TextBox1.value; }</script> 前几天刚好写过一个类似的东东。在父窗口中用脚本 window.open 打开新的窗口,这样在新的窗口中可以用 window.opener 对父窗口进行引用,window.opener 相当于父窗口中的 document 。另外,提醒一下,在父窗口中,不能用Label控件,客户端脚本无法操作Label控件,应该使用“System.Web.UI.HtmlControls.HtmlInputHidden”控件。这样可以将客户端改变的数字传入到服务器端。 全是客户端的操作呀,明白了,搞定,谢谢!this.opener.document.getElementById("txtModelPosition").value="OK";确实不能用Lable控件,用Label控件,虽然能够修改,但是提交后,值丢失了。改用TextBox就没事儿。(我把Label和TextBox都设置了只读属性) TextBox也可以,不过最好是HtmlInputHidden,节省数据量,提高性能。 如何把byte[]还原成Excel? 向DataTable中添加多行数据 解决问题马上给分 如何使用Image.Save方法发送图片到socket另一端? C#菜单栏选项事件只能使用一次的问题 各位高手帮帮我啊 高分求解,双网卡,Remoting时出错 一个幼稚的问题,请大家帮帮忙哈~~ 在sql数据库中如何存储Excel文件 在C#中怎样读取INI文件 如何从DataSet1中的一个表中读取一部分数据存入DataSet2中? 请教一个listview的显示问题。
openner对象就是父窗口了。
然后使用javascritp改变其中的一个span(就是你说的那个label)就可以。
1:Main.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Temp_Pop_Main" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button OnClientClick="OpenWin()" ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body></html>
<script>
function OpenWin()
{
var ReturnValue=new Array();
ReturnValue[0]=document.all.TextBox1.value;
window.showModalDialog("Pop.aspx",ReturnValue,"dialogHide:yes;dialogWidth:300px;dialogHeight:300px");
document.all.TextBox1.value =ReturnValue[0];
}
</script>2:Pop.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pop.aspx.cs" Inherits="Temp_Pop_Pop" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body onload="SetData()" onunload="GetData()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button OnClientClick="GetData();window.close();" ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>
<script>
var ResponseValue=window.dialogArguments;
function SetData()
{
document.all.TextBox1.value=ResponseValue[0];
}
function GetData()
{
ResponseValue[0]=document.all.TextBox1.value;
}
</script>
在父窗口中用脚本 window.open 打开新的窗口,这样在新的窗口中可以用 window.opener 对父窗口进行引用,window.opener 相当于父窗口中的 document 。
另外,提醒一下,在父窗口中,不能用Label控件,客户端脚本无法操作Label控件,应该使用“System.Web.UI.HtmlControls.HtmlInputHidden”控件。这样可以将客户端改变的数字传入到服务器端。
this.opener.document.getElementById("txtModelPosition").value="OK";
确实不能用Lable控件,用Label控件,虽然能够修改,但是提交后,值丢失了。改用TextBox就没事儿。(我把Label和TextBox都设置了只读属性)