WebForm aspx页面传值---7种方式
1、get方式
发送页
<form id="form1" runat="server">
<div>
<a href="WebForm2.aspx?name=5">调转到Form2</a>
<asp:Button ID="button2" Text="跳转页面" runat="server" onclick="button2_Click"/>
</div>
</form>
protected void button2_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx?name=5");
}
接受页
this.Label1.Text = Request["name"];
//this.Label2.Text = Request.Params["name"];
//this.Label3.Text = Request.QueryString[0];
2、post方式
a\不带 runat="server"形式
发送页
<form id="form2" action="WebForm2.aspx" method="post">
<input name="txtname" type="text" value="lilili" />
<input type="submit" value="提交网页" />
</form>
接受页
this.Label1.Text =Request.Form["txtname"];
b\带 runat="server"
发送页
<form runat="server" id="form3">
<input id="btnTransfer" type="button" onclick="post();" runat="server" value="跳转" />
</form>
<form id="form4" method="post">
<input type="text" runat="server" id="txtname" value="lili" />
</form>
<script type="text/javascript">
function post() {
form4.action = "WebForm2.aspx";
form4.submit();
}
</script>
接受页
this.Label1.Text =Request.Form["txtname"];
3、Session 和 Application
Session["name2"] = "sessontest";
Application["name3"] = "applicationtest";
this.Label2.Text =(string)Session["name2"];
this.Label3.Text =(string)Application["name3"];
4、静态变量
发送页
public static string statest="static string";
protected void button2_Click(object sender, EventArgs e)
{
Server.Transfer("WebForm2.aspx");
}
接受页
this.Label1.Text = WebForm1.statest;
5、Context.Handler 获取控件
发送页
<asp:TextBox ID="TextBox1" runat="server" Text="lilili"></asp:TextBox>
<asp:Button ID="button2" Text="跳转页面" runat="server" onclick="button2_Click"/>
protected void button2_Click(object sender, EventArgs e)
{
Server.Transfer("WebForm2.aspx");
}
接受页
//获取post传过来的对象
if (Context.Handler is WebForm1)
{
WebForm1 poster = (WebForm1)Context.Handler;
this.Label1.Text = ((TextBox)poster.FindControl("TextBox1")).Text;
}
6、Context.Handler 获取公共变量
发送页
public string testpost = "testpost";
protected void button2_Click(object sender, EventArgs e)
{
Server.Transfer("WebForm2.aspx");
}
接受页
//获取post传过来的对象
if (Context.Handler is WebForm1)
{
WebForm1 poster = (WebForm1)Context.Handler;
this.Label2.Text = poster.testpost;
}
7、Context.Items 变量
发送页
protected void button2_Click(object sender, EventArgs e)
{
Context.Items["name"] = "contextItems";
Server.Transfer("WebForm2.aspx");
}
接受页
//获取post传过来的对象
if (Context.Handler is WebForm1)
{
this.Label3.Text = Context.Items["name"].ToString();
}
WebForm aspx页面传值---7种方式的更多相关文章
- ios 页面传值4种方式(一) 之全局变量
通用的是用代理的方式实现页面传值,但是有时候利用其它方式也可以很巧妙的解决问题,页面传值一共有4种方式: 1.使用全局变量, SharedApplication,定义一个变量来传递. 2.使用文件,或 ...
- 【页面传值6种方式】- 【JSP 页面传值方法总结:4种】 - 【跨页面传值的几种简单方式3种】
阅读目录 1. URL 链接后追加参数 2. Form 3. 设置 Cookie 4. 设置 Session JSP 页面间传递参数是项目中经常需要的,这应该算是 web 基本功吧. 试着将各种方式总 ...
- ios 页面传值4种方式(四) 之通过delegate(代理)
这是ios里最常用的设计模式了,简直贯穿了整个cocoa touch框架.废话不多说,直接上代码: 场景是: A--打开--B; B里输入数值,点击--返回--A; A里显示B输入的值; △在开始写之 ...
- .net cs后台刷新aspx页面的四种方式
一:Response.Redirect(Request.Url.ToString()); 二:Response.Write("<script language=javascript&g ...
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据
WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...
- 网络笔记01-3 socket 实现百度页面的两种方式
scoket 实现百度页面的两种方式: 1.利用系统自带 //1.创建URL NSURL *url=[NSURL URLWithString:@"http://m.baidu.com& ...
- WebView加载页面的两种方式——网络页面和本地页面
WebView加载页面的两种方式 一.加载网络页面 加载网络页面,是最简单的一种方式,只需要传入http的URL就可以,实现WebView加载网络页面 代码如下图: 二.加载本地页面 1.加载asse ...
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)
WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...
- Controller传值到前端页面的几种方式
一丶追加字符串传值 #region 02-追加字符串传值 /// <summary> /// 02-追加字符串传值 /// </summary> /// <returns ...
随机推荐
- SET ANSI_NULLS ON ……
SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO 是什么意思? 语法 SET QUOT ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Log4J详解
Log4J 简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...
- 前端:IE兼容性的相关方法
有一段时间做前端的时候,IE下的就兼容性是比较令人头痛的问题,我在这一过程中也是看了很多的资料,然后把一些自己觉得比较普遍的问题进行一下相关的总结. 1.在IE6下,格式为png的图片在IE6上的透明 ...
- sqlmap的学习以及使用
PDF.NET(PWMIS数据开发框架)之SQL-MAP目标和规范 将复杂查询写到SQL配置文件--SOD框架的SQL-MAP技术简介 PDF.NET数据开发框架 之SQL-MAP使用存储过程 不懂还 ...
- MFC -- 遍历Dialog中的子元素(控件)
CWnd *win = GetWindow(GW_CHILD);//获取第一个子控件 while(win) { win代表子控件,可以通过win来获取子控件的信息,如下述两行代码 //iCtrlId ...
- js报错:email() is not a function
email() is not a function 明明是一个函数,但火狐控制台真J.. 由于JSP文件是别人写好直接使用的,所以,来回测试,折腾!最后,没办法,一段一段代码删除测试,才发现.有for ...
- js实现当前导航菜单高亮显示
为了增加用户体验度,增加网页的易用性和美观度,往往需要把当前导航菜单以特殊方式显示,通常是高亮显示或有不同于其它菜单的背景,有两种方法可以实现,第一种是用纯css来实现,二是用js辅助css来实现,两 ...
- PHP store session with couchbase
如何用couchbase存储session 有两种常见方式:1.采用memcache模式连接couchbase 只需两句修改: ini_set('session.save_handler', 'mem ...
- http 301和302的区别
1.什么是301转向?什么是301重定向? 301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种, ...