惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
L
LangChain Blog
Cyberwarzone
Cyberwarzone
美团技术团队
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
V
V2EX
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
aimingoo的专栏
aimingoo的专栏
人人都是产品经理
人人都是产品经理
F
Full Disclosure
V2EX - 技术
V2EX - 技术
The Cloudflare Blog
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Latest news
Latest news
S
Security @ Cisco Blogs
Spread Privacy
Spread Privacy
Project Zero
Project Zero
K
Kaspersky official blog
MyScale Blog
MyScale Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
罗磊的独立博客
Vercel News
Vercel News
N
News and Events Feed by Topic
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes

博客园 - hzman

ASP采集入库生成本地文件的几个FUCTION 用XMLhttp编写web采集程序 无需安装软件架设NOD32升级服务器指南! 架设NOD32升级服务器 - hzman - 博客园 C#游戏外挂代码 VC7转换到VC8的常见问题 ini文件操作类 OllyDBG 入门系列(二)-字串参考 OllyDBG 入门系列(一)-认识OllyDBG - hzman - 博客园 live.cn邮箱注册帐号方法 - hzman - 博客园 免手机验证码网站备案 ASP同一虚拟空间放多个站点(各站点对应独立域名)的方法 QQ空间代码说明 C#代码,功能为拦截http请求,并篡改其中任何内容 C#编写NotifyIcon 深入浅出之正则表达式 两个分析HTML网页的方法 提取HTML代码中文字的C#函数 c#字符串截取函数
页面间传值方法
hzman · 2007-07-16 · via 博客园 - hzman

如果在两个页面间需要大量的参数要传传递,如数据查询等页面时,用1 - 6的方法传值及其不便,而第 7 种方法确有一独特的优势!但使用该方法时需要一定的设置,现简单介绍一下该方法的使用方式:
   以查询数据页面为例:
   在查询页面中设置如下公有属性(QueryPage.aspx):

    public class QueryPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtStaDate;
protected System.Web.UI.WebControls.TextBox txtEndDate;
   ...
/// <summary>
/// 开始时间
/// </summary>
public string StaDate
{
get{ return this.txtStaDate.Text;}
set{this.txtStaDate.Text = value;}
}
/// <summary>
/// 结束时间
/// </summary>
public string EndDate
{
get{ return this.txtEndDate.Text;}
set{this.txtEndDate.Text = value;}
}
....
private void btnEnter_Click(object sender, System.EventArgs e)
{
Server.Transfer("ResultPage.aspx");
}


      在显示查询结果页面(ResultPage.aspx):

    public class ResultPage : System.Web.UI.Page
{
   private void Page_Load(object sender, System.EventArgs e)
   {

//转换一下即可获得前一页面中输入的数据
QueryPage queryPage = ( QueryPage )Context.Handler;

Response.Write( "StaDate:" );
Response.Write( queryPage.StaDate );
Response.Write( "<br/>EndDate:" );
Response.Write( queryPage.EndDate );
  }

如果有许多查询页面共用一个结果页面的设置方法:
    在这种方式中关键在于“ QueryPage queryPage = ( QueryPage )Context.Handler; ”的转换,只有转换不依赖于特定的页面时即可实现。
如果让所有的查询页面都继承一个接口,在该接口中定义一个方法,该方法的唯一作用就是让结果页面获得构建结果时所需的参数,就可实现多页面共享一个结果页面操作!

1、先定义一个类,用该类放置所有查询参数:


/// <summary>
/// 结果页面中要用到的值
/// </summary>
public class QueryParams
{
private string staDate;
private string endDate;

/// <summary>
/// 开始时间
/// </summary>
public string StaDate
{
get{ return this.staDate;}
set{this.staDate = value;}
}
/// <summary>
/// 结束时间
/// </summary>
public string EndDate
{
get{ return this.endDate;}
set{this.endDate = value;}
}


2、接口定义:

/// <summary>
/// 定义查询接口。
/// </summary>
public interface IQueryParams
{
/// <summary>
/// 参数
/// </summary>
QueryParams Parameters{get;}


3、查询页面继承IQueryParams接口(QueryPage.aspx):

/// <summary>
///查询页面,继承接口
/// </summary>
public class QueryPage : System.Web.UI.Page, IQueryParams
{
protected System.Web.UI.WebControls.TextBox txtStaDate;
protected System.Web.UI.WebControls.TextBox txtEndDate;

private QueryParams queryParams;
   ...
/// <summary>
/// 结果页面用到的参数
/// </summary>
   public QueryParams Parameters
{
get
{
return queryParams;
}
}
....
private void btnEnter_Click(object sender, System.EventArgs e)
{
//赋值
queryParams = new QueryParams();
queryParams.StaDate = this.txtStaDate.Text;
queryParams.EndDate = this.txtEndDate.Text

Server.Transfer("ResultPage.aspx");
}

别外的页面也如此设置
5、接收页面(ResultPage.aspx):

public class ResultPage : System.Web.UI.Page
{
   private void Page_Load(object sender, System.EventArgs e)
   {

QueryParams queryParams = new QueryParams();
IQueryParams queryInterface;
//实现该接口的页面
if( Context.Handler is IQueryParams)
{
queryInterface = ( IQueryParams )Context.Handler;
queryParams = queryInterface.Parameters;
}

Response.Write( "StaDate:" );
Response.Write( queryParams.StaDate );
Response.Write( "<br/>EndDate:" );
Response.Write( queryParams.EndDate );
  }
}