日期:2014-05-18  浏览次数:20492 次

2个aspx页面,如何互相传递值?
比如说有2个aspx   页面,

WebForm1   上有一个文本框   和   一个按钮。

WebForm2   上也有一个文本框   和   一个按钮。

现在我想实现,
1.首先打开WebForm1,在文本框中随便输个值“ABC”,然后点击按钮,这个时候要   能打开   WebForm2,并且WebForm2上的文本框的值   和   WebForm1   上的   一样!

2.接下来,我随便修改一下WebForm2上的文本框的值,点击按钮,这个时候WebForm2关闭,然后修改後的值传回WebForm1上的文本框。

谢谢!我是新手,大家别奸笑!
最好能给段代码,参考一下!


------解决方案--------------------
// WebForm2.aspx

<script type= "text/javascript ">
function applyToParent() {
var winParent = window.opener;
if(!winParent) alert( "父窗口不存在。 ");
winParent.document.getElementById( "txtInParentWin ").value
= document.getElementById( "txtInChildWin ").value;
}
</script>

<input id= "btnClose " type= "button " value= "Close " onclick= "applyToParent();window.close(); " />

------解决方案--------------------
第一个页面的代码
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Name=Request.QueryString[ "Name "];
this.TextBox1.Text = Name;
}
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect( "Default2.aspx?Name= "+this.TextBox1.Text.Trim());
}
}

第二个页面的代码
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string Name = Request.QueryString[ "Name "];
this.TextBox1.Text = Name;
}
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write( " <script> window.location.href= 'Default.aspx?Name= " + this.TextBox1.Text.Trim() + " '; </script> ");
}
-----------------------
Response.Write( " <script> window.location.href= 'Default.aspx?Name= " + this.TextBox1.Text.Trim() + " '; </script> ");
这里让它关闭窗口我没有写你自己找找写上吧!这里是在VS05里面做的只做参考写的不好
忘不要笑话
------解决方案--------------------
不用JS貌似也可以,不过代码不够优化,性能不好。