一 个页面的前台textbox1.text的数据 怎么传到另一个页面的后台页面(CS文件

aaa6965921aaa 2010-07-24 03:21:21
一 个页面的前台textbox1.text的数据 怎么传到另一个页面的后台页面(CS文件) 难道一定要用 地址参数传递吗
URL?ID=textbox1.text??对吗
...全文
247 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzjxylophone 2010-07-25
  • 打赏
  • 举报
回复
帮顶。
gohappy2008 2010-07-25
  • 打赏
  • 举报
回复
也可以用session、cookie啊
studentliudong 2010-07-24
  • 打赏
  • 举报
回复
方式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对象将是最佳的选择



方法4:

发送页:
1.定义静态变量: public static string str="";
2. str=this.TextBox1.Text;
Server.Transfer("webform2.aspx");
接收页:
1.引入第一页的命名空间:using WebApplication1;
2 this.TextBox1.Text=WebForm1.str;
jackyzsy2008 2010-07-24
  • 打赏
  • 举报
回复
session,cookie,url...方法很多,根据实际情况选择合适的方法。
周公 2010-07-24
  • 打赏
  • 举报
回复

<%
//如果没有设置名为"ApplicationCount"的Application
int applicationCount=1;
int sessionCount=1;
if(Application["ApplicationCount"]==null)
{
Application["ApplicationCount"]=1;
}
else//否则取出该Session,并且在当前值上加1
{
applicationCount=(int)Application["ApplicationCount"]+1;
Application["ApplicationCount"]=applicationCount;
}
//如果Session["SessionCount"]为空,即没有设置该名字的Session
if(Session["SessionCount"]==null)
{
Session["SessionCount"]=1;
}
else
{
sessionCount=(int)Session["SessionCount"]+1;
Session["SessionCount"]=sessionCount;
}
Response.Write("当前页面由Application记录到的被访问了"+applicationCount+"次<br/>");
Response.Write("当前页面由Session记录到的被访问了"+sessionCount+"次<br/>");
%>
周公 2010-07-24
  • 打赏
  • 举报
回复
名称
使用范围
存储位置
存放数据类型
生命周期

Session
特定用户
服务器
Object,也就是任意类型
有,可以自行设置

Cookie
特定用户
客户端
String,也就值字符串
可以自行设置

Application
所有用户
服务器
Object,也就是任意类型


周公 2010-07-24
  • 打赏
  • 举报
回复
Asp.net夜话之二:asp.net内置对象
准确地说,asp.net并没有内置对象这一说,jsp里确实把request、response这些当作jsp的内置对象,这里只不过是借用了一下jsp的说法而已。上面提到的很多都是在做asp.net开发时无需new就能使用的对象(类似的还有很多,在asp.net中所有的网页都是继承自System.Web.UI.Page这个类,上面的提到多是Page类的属性)。本文介绍System.Web.UI.Page类的几个常用属性,如Request、Response、Server、Session、Cookie、Application,并讲述了及表达式用法。
wuyq11 2010-07-24
  • 打赏
  • 举报
回复
session,cookie
server.Transfer
Request.QueryString都可实现
Peter200694013 2010-07-24
  • 打赏
  • 举报
回复
可以用url传值,也可以用session

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧