找到一段代码:高手帮我看看,能实现任意页面传值吗?
private void Button1_Click
(object sender, System.EventArgs e)
{
 //textbox1 and textbox2 are webform
 //controls
 Session["name"]=TextBox1.Text;
 Session["email"]=TextBox2.Text;
 Server.Transfer("anotherwebform.aspx");
}
  目标页面代码:
private void Page_Load
(object sender, System.EventArgs e)
{
 Label1.Text=Session["name"].ToString();
 Label2.Text=Session["email"].ToString();
 Session.Remove("name");
 Session.Remove("email");
}

解决方案 »

  1.   

    为什么我在c.aspx里写
    Server.Transfer("anotherwebform.aspx");
    数据是传回a.aspx了,但是a.aspx页显示在了c.aspx页里了。。
    c.aspx是一个弹出的,定好了大小的窗口。。
    怎么样才能让a.aspx页保持原来的样子呢?
      

  2.   

    如果使用window.open方式打开窗口Response.Write("<script language=javascript>window.opener.opener.document.Form1.submit();</script>");
    Response.Write("<script language=javascript>window.close();</script>");
      

  3.   

    再加上
    Response.Write("<script language=javascript>window.opener.close();</script>");
      

  4.   

    用session[]
    也可以用隐含控件
      

  5.   

    还是一个啊。。
    我现在只用两个页试。
    a.aspx还是出现在b.aspx页里中。。
    a.aspx是框架的一个页面。Server.Transfer("anotherwebform.aspx");
    这一句是不是只能在当前传值页面里打开anotherwebform.aspx页面呢?
    在按钮事件里加
    Response.Write("<script language=javascript>window.close();</script>");
    也不行,当前窗口关不了,直接链接到了anotherwebform.aspx
    ????
      

  6.   

    session,查询参数,隐藏字段。
      

  7.   

    你们可能误解了
    传值是没有问题啊
    问题是从b.aspx和c.aspx得到两个变量传给a.aspx后。。
    a.aspx直接显示在了c.aspx页面中。。
    b.aspx,c.aspx是一个定制大小的窗口。。a.aspx是框架中一个页面。。
      

  8.   

    页面之间传递值方式1:
        
    在接收页 的html代码里加上一行: <%@ Reference Page = "WebForm1.aspx" %>            
         
        WebForm1 fp=(WebForm1)Context.Handler;
        this.TextBox1.Text=fp.name;   //name 是第一页的public变量
    Context  提供对整个当前上下文(包括请求对象)的访问。您可以使用此类共享页之间的信息。 方式2:GET方式
        在发送页
          public int sum=0;           int i =int.Parse(this.TextBox1.Text)*2;           Server.Transfer("WebForm2.aspx?sum="+i);    接收页
            this.TextBox1.Text=Request["sum"].ToString();
        or  this.TextBox1.Text=Request.Params["sum"].ToString();
            this.TextBox1.Text=Request.QueryString["sum"];
    方法3:全局变量   发送页:
           Application["sum"]=this.TextBox1.Text;
           Server.Transfer("WebForm2.aspx");   接收页:
           this.TextBox1.Text=(string)Application["sum"];Application实质上是整个虚拟目录中所有文件的集合,如果想在整个应用范围内使用某个变量值,Application对象将是最佳的选择在这里用Session[""]的方法雷同方法4: 发送页:
        1.定义静态变量:  public static string str="";
        2. str=this.TextBox1.Text;
           Server.Transfer("webform2.aspx");
     接收页:
        1.引入第一页的命名空间:using WebApplication1;
        2  this.TextBox1.Text=WebForm1.str;