用户名: 密码: 免费注册 忘记密码? 网站地图 | 加入收藏 | 设为首页
首页 | 新闻 | 工具 | 系统 | 办公 | 聊天 | 多媒体 | 网页 | 运营 | 平面 | 欣赏 | 数据库 | 程序 | 服务器 | 组网
网页 | 3dmax | Ghost | Windows Xp| Dreamweaver | photoshop | Flash | office | Alexa | Css | QQ | Asp | PHP | Jsp | Access
Flash MX 2004入门 | 网站推广策略 | CorelDRAW入门 | ASP学习 | 网站建设大师功 | Word入门
  iTbulo.com > 学院 > 程序开发教程 > ASP教程 > ASP实例教程 > 文章正文
Web程序中网页间数据传递方法小结
iTbulo.COM 2006-1-4 未知()

Session Variables

接下来我们看一看session变量,这些变量由服务器来处理。第一个响影一从客户端传递到服务器,Sessions就创建了,并且当用户关闭浏览器窗口或者一些异常操作发生,session就会结束。给你一些可以使用session变量来传递数值的方法。在下面你看到为用户创建的Session和 “Name”是关键字,也如知名的Session关键字一样,关键字被赋给TextBox数值。

// Session Created

Session["Name"] = txtName.Text;

Response.Redirect("WebForm5.aspx");

// The code below shows how to get the session value.

// This code must be placed in other page.

if(Session["Name"] != null)

Label3.Text = Session["Name"].ToString();

Application Variables

有时,我们需要存取来自网页任何地方的数值。因为那样,可以使用Application变量。这里有一小段代码,这段代码显示如何做到那些事情。一旦创建Application变量并且为其赋值,在应用程序的任何地方都可以重新得到它的值。

// This sets the value of the Application Variable

Application["Name"] = txtName.Text;

Response.Redirect("WebForm5.aspx");

// This is how we retrieve the value of the Application Variable

if( Application["Name"] != null )

Label3.Text = Application["Name"].ToString();

HttpContext

可以使用HttpContext从网页中重新得到数值。通过使用方法的属性获得那些数值。既然它们易于编写代码和修改,使用属性是一种好方法。在你的第一个网页中,制造一个属性,这个属性可以返回TextBox的值。

public string GetName

{

get { return txtName.Text; }

}

我们使用Server.Transfer来将此控件发送到一个新网页。注意:Server.Transfer仅仅将此控件传递到新的网页并且不重新定位该网页,这意味着你会看到在URL中旧网页的地址。简单地在“Server.Transfer”按钮单击事件,并且增加下列代码。

Server.Transfer("WebForm5.aspx");

现在,让我们定位网页,数值就传递到该网页上,在这种情况下使用的该网页是“webForm5.aspx”。

// You can declare this Globally or in any event you like

WebForm4 w;

// Gets the Page.Context which is Associated with this page

w = (WebForm4)Context.Handler;

// Assign the Label control with the property "GetName" which returns string

Label3.Text = w.GetName;

Special Note

特别注意 与你看到的一样,从一个网页向别一网页传递数值时有不同的方法。每一个方法有它自己的优点也有其缺点。所以,当你传递数值时,选择好你所需要的所以你就会有一种好方法,这种方法对你是最为可行的。

上一页  [1] [2] 

文章搜索
相关资讯
相关文章 相关下载
破解网站发布系统 ASP生成静态页面方法
IE浏览器防黑十大秘技
ASP六大对象介绍
经典!5分钟编写一个ASP论坛
ASP程序性能测试报告
焦点信息