ASP.NET 2.0 中实现跨页提交:一般都是两个页面相互切换是实现的!
我现在在一个页面(旧)中有个按钮,单击后出现一个比较小的页面(新),这是页面(旧)就在页面(新)的下方还能看到!!页面(新)中一个按钮,单击后把页面(新)关掉,并把一个string的值传到页面(旧)的 TextBox中,如何实现?
请各位指教,谢谢,非常感谢!!
我现在在一个页面(旧)中有个按钮,单击后出现一个比较小的页面(新),这是页面(旧)就在页面(新)的下方还能看到!!页面(新)中一个按钮,单击后把页面(新)关掉,并把一个string的值传到页面(旧)的 TextBox中,如何实现?
请各位指教,谢谢,非常感谢!!
解决方案 »
- c# socket 出现无反应?
- 求winform中Tree和GridView结合的第三方控件或解决办法
- sql server导出至access,如解决问题,感激涕零加100分相送。
- 定义了DataSet中DataTable的Columns,如何读入对应的数据
- 查msdn还有一事不明
- 在C#中,怎样设置窗体Form,在它Show时,只有它得到焦点呢?
- 一个困惑的验证问题,谁能帮忙想办法?
- server端向client端连续发送图片时,client端的接收如何处理?
- 关于winform的小问题(急)
- 请问这种点对点聊天思路可行不!?
- 处理DataGridView.RowHeaderMouseClick事件
- 新手!关于c#程序的移机问题~!
1、可以通过Session
2、在旧页面中定义一个静态static的string变量
来实现
里面可以写返回值(旧)var yourstring = window.showModalDialog(......)
(新)window.returnValue = yourstring
要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如: test1.htm
====================
<script>
var mxh1 = new Array("mxh","net_lover","孟子E章")
var mxh2 = window.open("about:blank","window_mxh")
// 向对话框传递数组
window.showModalDialog("test2.htm",mxh1)
// 向对话框传递window对象
window.showModalDialog("test3.htm",mxh2)
</script> test2.htm
====================
<script>
var a = window.dialogArguments
alert("您传递的参数为:" + a)
</script> test3.htm
====================
<script>
var a = window.dialogArguments
alert("您传递的参数为window对象,名称:" + a.name)
</script> 可以通过window.returnvalue向打开对话框的窗口返回信息,当然也可以是对象。例如: test4.htm
===================
<script>
var a = window.showModalDialog("test5.htm")
for(i=0;i<a.length;i++) alert(a[i])
</script> test5.htm
===================
<script>
function sendTo()
{
var a=new Array("a","b")
window.returnvalue = a
window.close()
}
</script>
<body>
<form>
<input value="返回" type=button onclick="sendTo()">
</form>
window.returnvalue 返回值时,可以得到服务器控件TextBox.Text吗?
返回的值是不是只是客户端能看都,服务器控件根本不知道它的值已经改变了?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<input id="Text1" type="text" />
<input id="Button1" type="button" value="button" onclick="window.open('a.aspx', '_blank', 'width=400,height=300')" />
</form>
</body>
</html>a.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="a" %><!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>Untitled Page</title>
<script type="text/javascript">
function btn_click() {
window.opener.document.getElementById('Text1').value = document.getElementById('param').value;
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="param" /><input type="button" value="Close" onclick="btn_click();"
</form>
</body>
</html>
document.getElementById("<%= TextBox1.ClientID %>");
你举的例子可以用,谢谢!
但是,我的都是服务器控件,用document.getElementById("<%= TextBox1.ClientID %>")提示:当前上下文中不存在TextBox1!
有时候提问问题者请自行理解某些问题~
如果连基本功都没掌握,即使别人给出了该怎么做的方案,提问者还是不懂就是个人修为的问题了~
document.getElementById("<%= TextBox1.ClientID %>")
这个是使用了嵌入式代码块 (Embedded Code Blocks)
Embedded Code Blocks
帮助是这么写di:
嵌入式代码块中,语法 <% = expression %> 用于解析表达式,并将其值返回到块中。
下面的代码示例演示一个嵌入式代码块,该代码块显示 span 元素中的公共 GetTime() 函数的值。在嵌入式代码块中,语法 <% = expression %> 用于解析表达式,并将其值返回到块中。
<%@ Page Language="C#" %>
<script runat=server>
protected String GetTime()
{
return DateTime.Now.ToString("t");
}
</script>
<html>
<body>
<form id="form1" runat="server">
Current server time is <% =GetTime()%>.
</form>
</body>
</html>
是window.opener.document.getElementById("<%= Text1.ClientID %>")提示:当前上下文中不存在TextBox1!
因为default.aspx中我用的是服务器控件 TextBox!
谢谢!!
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
window.onload = function() {
document.getElementById("<%= TextBox1.ClientID %>").value = "wjs";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="D.aspx.cs" Inherits="D" %>
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" onclick="window.open('a.aspx', '_blank', 'width=400,height=300')" />
<br />
<asp:TextBox ID="txtBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>页面:a.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="a" %><!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 id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function btn_click() {
window.opener.document.getElementById("<%= txtBox1.ClientID %>").value = document.getElementById("<%= TextBox1.ClientID %>").value;
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input type="button" value="Close" onclick="btn_click();" />
</form>
</body>
</html>
提示:当前上下文中不存在txtBox1!
window.opener.document.getElementById("<%= txtBox1.ClientID %>").
厄~,<%是嵌入块,只能使用当前页面的服务器控件,而window.opener是指当前页的打开者,即是你点了按钮打开了当前页面的那个页面,厄~,楼主的水平未免太菜了~
在页面(旧)中<input type="text" id="param" runat="server"/>就可以了,非常感谢!