Server.Transfer页面跳转传递控件值得解决方案

简介: 今天在CSDN上看到这个问题,特写了个解决方案,供参考.  问题描述:在Default2.aspx页面中点击按钮将TextBox1控件的值传递到Default3.aspx页面中去,供Default3.aspx页面使用。

今天在CSDN上看到这个问题,特写了个解决方案,供参考.

 

问题描述:在Default2.aspx页面中点击按钮将TextBox1控件的值传递到Default3.aspx页面中去,供Default3.aspx页面使用。

 

关键点有2点:

1、Server.Transfer("Default3.aspx", true);  //方法第二个参数为true

 

2、对于跳转到的页面的头部要添加跳转页面类得引用,<%@ Reference Page="Default2.aspx"%>,如果Default2.aspx在某个文件夹下的话,如Admin文件夹下的话,得这样写:<%@ Reference Page="Admin_Default2.aspx"%>(即是该页面类后台cs文件的完整类名,这个得尤其注意)

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       

    }
    public string name
    {
        get
        {
            return TextBox1.Text;
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("Default3.aspx", true);
    }
}


==========================================================================

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Reference Page="Default2.aspx"%>
<!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>
   
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strTxt = "";
            Default2 oForm = (Default2)this.Context.Handler;
            strTxt += "Default2页面中TextBox1文本框中的值为:" + oForm.name + "<br>";
            Response.Write(strTxt);
        }
    }
}


 


相关文章
|
6月前
|
缓存
SAP UI5 OData 请求的自定义 HTTP header 设置方法
SAP UI5 OData 请求的自定义 HTTP header 设置方法
37 0
|
7月前
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求 2
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求
53 0
|
7月前
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求 1
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求
54 0
|
7月前
|
API Apache Perl
关于 Spartacus 服务器端渲染出现 timeout 的一个具体例子的分析
关于 Spartacus 服务器端渲染出现 timeout 的一个具体例子的分析
43 0
|
7月前
|
存储 缓存 前端开发
Web Server 设置缓存响应字段的一些推荐方案
Web Server 设置缓存响应字段的一些推荐方案
47 1
|
7月前
|
存储 监控 JavaScript
SAP 电商云 Spartacus UI set delivery mode HTTP put 请求的触发时机
SAP 电商云 Spartacus UI set delivery mode HTTP put 请求的触发时机
31 0
|
前端开发 JavaScript 编译器
第三十三章 使用 CSP 进行基于标签的开发 - 使用Hyperevents #server和#call调用服务器端方法
第三十三章 使用 CSP 进行基于标签的开发 - 使用Hyperevents #server和#call调用服务器端方法
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求(一)
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求
110 0
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求(一)
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求(二)
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求
70 0
SAP 电商云 Spartacus UI 修改 Delivery Mode 触发的三个 HTTP 请求(二)
|
XML 前端开发 JavaScript
Web---监听用户名注册技术-myAJax-隐藏帧
Web---监听用户名注册技术-myAJax-隐藏帧
114 0