asp.net(c#)网页跳转 方法小结
| 返回 打印 |
|
asp.net(c#)网页跳转七种方法小结_实用技巧_脚本之家
在asp.net下,经常需要页面的跳转,下面是具体的几种方法。跳转页面是大部编辑语言中都会有的,正面我们来分别介绍一下关于.net中response.redirect sever.execute server.transfer 三种页面跳转的方法
①response.redirect 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次 postback),但他可以跳 转到任何页面,没有站点页面限制(即可以由雅虎跳到新浪),同时不能跳过登录保护。但速度慢是其最大缺陷!redirect跳转机制:首先是发送一个 http请求到客户端,通知需要跳转到新页面,然后客户端在发送跳转请求到服务器端。需要注意的是跳转后内部空间保存的所有数据信息将会丢失,所以需要用 到session。 实例 Example that uses Redirect [C#; ASP.NET] 复制代码 代码如下:
using System;
using System.Web.UI; namespace WebApplication1 { public partial class List : Page { protected void Page_Load(object sender, EventArgs e) { // Get response. var response = base.Response; // Redirect temporarily. // ... Don't throw an HttpException to terminate. response.Redirect("http://www.jb51.net", false); } } } Result of the page 复制代码 代码如下:
HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8 Location: http://www.jb51.net Server: Microsoft-IIS/7.0 Date: Fri, 13 Aug 2010 21:18:34 GMT Content-Length: 144 <html><head><title>Object moved</title></head><body> <h2>Object moved to <a href="http://www.dotnetperls.com/list">here</a>.</h2> </body></html> ②sever.execute 复制代码 代码如下:
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 复制代码 代码如下:
private void Page_Load
(object sender, System.EventArgs e) { //创建原始窗体的实例 WebForm1 wf1; //获得实例化的句柄 wf1=(WebForm1)Context.Handler; Label1.Text=wf1.Name; Label2.Text=wf1.EMail; } ③server.transfer 复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form> </body> </html> .net代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class WebForm1 : System.Web.UI.Page { public string Time { get { return DateTime.Now.ToString(); } } public string TestFun() { return "Function of WebForm1 Called"; } protected void Page_Load(object sender, EventArgs e) { Context.Items.Add("Context", "Context from Form1"); } protected void Button1_Click(object sender, EventArgs e) { //this.TextBox2.Text =Request ["TextBox1"].ToString (); Server.Transfer("WebForm2.aspx", true);//第二个参数为false时,WebForm2.aspx中不能获得TextBox1的内容 } } 总结: 来源于脚本之家:http://www.jb51.net/article/21046.htm |
asp.net(c#)网页跳转 方法小结的更多相关文章
- asp.net(c#)网页跳转七种方法小结
在asp.net下,经常需要页面的跳转,下面是具体的几种方法.跳转页面是大部编辑语言中都会有的,正面我们来分别介绍一下关于.net中response.redirect sever.execute se ...
- 【转】【Asp.Net】asp.net(c#) 网页跳转
在asp.net下,经常需要页面的跳转,下面是具体的几种方法.跳转页面是大部编辑语言中都会有的,正面我们来分别介绍一下关于.net中response.redirect sever.execute se ...
- 【转】【Asp.Net】Asp.net发送邮件的两种方法小结
这几天看了一下Asp.net发送邮件方面的东西,记得之前的IIS6上有SMTP服务器,可以直接利用这个进行邮件发送,现在的开发环境是Windows 7,找了半天没有找到,到网络上查了才知道原来wind ...
- JavaWeb学习笔记--跳转方法小结
服务端跳转:1. RequestDispatcher.forward() public void doGet(HttpServletRequest request, HttpServletRespo ...
- asp.net session丢失的解决方法小结
现在我就把原因和解决办法写出来. ASP.NET Session丢失原因: 由于Asp.net程序是默认配置,所以Web.Config文件中关于Session的设定如下: < sessionSt ...
- asp.net中几个网页跳转的方法及区别
1:注意:Response.Redirect("a.html")是不能跳出框架.IFRAME的. 可以使用 Response.Write("<script Lang ...
- 使用IE11抓包,防止在网页跳转时抓包数据被清除的方法
引:最近在研究使用python实现模拟登陆各大网站,在使用IE11进行抓包分析网站登陆的逻辑结构的时候,发现每次在抓包的时候,当网页跳转的时候,抓包数据会被清除,让我很是郁闷,最终在查阅相关资料以及自 ...
- asp.net检查验证字符串是否为纯数字方法小结
原文 asp.net检查验证字符串是否为纯数字方法小结 在asp.net中验证字符串是不是为数字我们没有像php中那么多丰富的函数来直接使用,这里我整理了一些比较实例的验证字符串是否为纯数字方法代码 ...
- 小结php中几种网页跳转
1.使用网页中<a href=.....></a>实现跳转: 2.<form action="php_request2.php" method=&qu ...
随机推荐
- 循环结构while
Note:高能:语句结构都是由关键字开头,用冒号结束! 一:语句结构 while 判断条件: 语句 二:基本规则 (1)使用缩进来划分语句块,相同缩进数的语句在一 ...
- 泡泡一分钟:Cooperative Object Transportation by Multiple Ground and Aerial Vehicles: Modeling and Planning
张宁 Cooperative Object Transportation by Multiple Ground and Aerial Vehicles: Modeling and Planning 多 ...
- Exp5 MSF基础应用 20164320 王浩
1. 实践目标 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.1一个主动攻击实践,如ms08_067; (1分) 1.2 一个针对浏览器的攻击, ...
- Mac OSX bash function 备份
# mount the android file image function mountAndroid { hdiutil attach ~/android.dmg.sparsefile.spars ...
- Java学习--抽象类和接口
https://www.cnblogs.com/dolphin0520/p/3811437.html 抽象类 先了解一下[抽象方法]—一种特殊的方法,只有声明,没有具体的实现 abstract vo ...
- PHP生成当前月份包括最近12个月内的月份
直接上代码: $time=array(); $currentTime = time(); $cyear = floor(date("Y",$currentTime)); $cMon ...
- java中使用springmvc实现下载文件
下载文件具体实现代码: public class TestDownload{ public HttpServletRequest request; public HttpServletResponse ...
- webpack(6)-模块热替代&tree shaking
模块热替换(hot module replacement 或 HMR) 模块热替换(hot module replacement 或 HMR)是 webpack 提供的最有用的功能之一.它允许在运行时 ...
- vue中使用vue-quill-editor及上传图片到自己服务器
第一步,下载依赖 cnpm install vue-quill-editor --save 第二步,再main.js里引入组件(我这里是全局注册) // 富文本编辑器 import VueQuillE ...
- PHP----------php的opcache扩展配置参数介绍
[opcache]zend_extension = "路径/ext/php_opcache.dll" ; Zend Optimizer + 的开关, 关闭时代码不再优化.opcac ...