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 ...
随机推荐
- 关于SQLite3笔记
sq .help .quit .exit 创建和连接数据库:在linux中 sqlite3 数据库名 没有就创建 有就连接 .show 显示各种设置的当前值. .echo ON|OFF echo命令 ...
- Python读取xlsx翻译文案
首先安装Python,然后安装模块 //查找模块(非必须) pip search xlrd //安装模块 pip install xlrd 由于输出要是utf-8所以需要设置默认环境为utf-8 # ...
- [ipsec][crypto] 在IPSec ESP使用AES-GCM加密时的IV
IV IV是指初始化向量. 在我们当前讨论的场景中: 在IPSec ESP使用AES-GCM加密 IV有两个含义: 1. ESP报文封装时的IV,RFC中称为 AES-GCM IV +-+-+-+-+ ...
- iview 表单非空验证
rules: { title: [ {required: true, message: '请填写栏目名称', trigger: 'blur'} ], desc: [ {required: true, ...
- webpack摸索笔记
上一个链接,入门webpack看这篇文章最好:https://segmentfault.com/a/1190000006178770 1.先安装好node 2.建个项目文件 3,.window+r,打 ...
- Python002-操作MSSQL(Microsoft sql server)基础示例(二)
前文http://www.cnblogs.com/fengpingfan/p/7675291.html,讲述了python操作mssql的步骤.环境创建.常用方法等,本文将实例演示python操作ms ...
- Mybatis-Plus 3.0代码生成器
package com.kyplatform.generator; import com.baomidou.mybatisplus.core.exceptions.MybatisPlusExcepti ...
- POJ2762 Going from u to v or from v to u? 强连通分量缩点+拓扑排序
题目链接:https://vjudge.net/contest/295959#problem/I 或者 http://poj.org/problem?id=2762 题意:输入多组样例,输入n个点和m ...
- Azure架构(一):云计算基础
云计算的定义 云计算(英语:cloud computing),是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需求提供给使用各种计算终端(桌面电脑.笔记本电脑.平板电脑.手机等) ...
- svg合并
假如页面有多个svg图标要加载,多次加载不利,可将多个svg合并为一个加载 如下有两个svg <svg xmlns="http://www.w3.org/2000/svg" ...