http://www.csdn.net/Develop/Article/21/21539.shtm
解决方案 »
- 服务器部署Oracle.DataAccess的问题
- uniqueidentifier类型的数据是否可以和字符串进行比较运算?
- 装完 windows server2003后,添加或删除程序中没有“Internet信息服务”这一项是怎么回事??
- 给ImageButton添加图像以及上传文件路径不能有空格的问题
- 菜鸟,菜采鸟,提问!
- 我在这里深情的等待作为高手的你!!!(gridview)
- 关于 DropDownList 的取值问题,急啊!~~~~~~~~~~~~
- 从工具箱中拖一个连接对象到页面里,虽然能设置其各个属性,但为什么在代码里看不到这个 东西
- 关于数据库连接的问题!急,谢谢
- [][]谁有有用Microsoft Visio制作的项目计划[进度]图示吗?[可以提供出来]
- 导入命名空间的问题````大家请帮帮忙````
- 我遇到了一些问题,各位帮帮忙!
在接收页 的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;
server.transer("newpage.aspx?name=" + strName);或者定义属性在新页面调用就可以了
Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象。如果你想传递一个安全性不是那么太重要或者是一个简单的数值时,用此方法最好不过了。下面通过一个小例子来完成传值工作,步骤如下:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
string url;
url="webform2.aspx?name=" +
TextBox1.Text + "&email=" +
TextBox2.Text;
Response.Redirect(url);
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
运行,即可看到传递后的结果了。 二、使用Session变量 使用Session变量传值是一种最常见的方式了,此中方式不仅可以把值传递到下一个页面,还可以交叉传递到多个页面,直至把Session变量的值removed后,变量才会消失。举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
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");
}
运行,即可看到传递后的结果了。 三、使用Server.Transfer
虽然这种方法有点复杂,但也不失为一种在页面传值的方式。
举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("webform2.aspx");
}
4、创建过程来返回TextBox1,TextBox2控件的值代码如下:
public string Name
{
get
{
return TextBox1.Text;
}
} public string EMail
{
get
{
return TextBox2.Text;
}
}
5、新建一个目标页面命名为webform2
6、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
//创建原始窗体的实例
WebForm1 wf1;
//获得实例化的句柄
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail; }
运行,即可看到传递后的结果了。
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"];....................一个比一个清楚啊!!!^_^