Response.Redirect 打开这两种方法的一种新形式
在一般情况下。Response.Redirect 该方法是在server年底转向,因此,除非 Response.Write("<script>window.location='http://dotnet.aspx.cc';</script>") 方法外,是不能在新窗体打开所指定的 URL 地址的。可是,假设细致分析一下。假设设置 form 元素的 target 属性,还是有办法打开新窗体的。以下就是能够採用的两种方法。
方法一:在server端设置 target 属性,这种方法也很适用于client不支持脚本的情况。
代码例如以下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
form1.Target = "_blank";
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://dotnet.aspx.cc");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body id="b" runat="server">
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="打开新窗体或者新 Tab " />
</form>
</body>
</html>
办法二:採用client脚本的方法设置 target 属性。代码例如以下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "this.form.target='_newName'");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://dotnet.aspx.cc");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body id="b" runat="server">
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="打开新窗体或者新 Tab " />
</form>
</body>
</html>
上面两种方法中的 target 属性能够採用不论什么合法的名称。但要注意,假设同样名称的窗体已经打开,则新窗体会在已经存在名称的窗体里打开。
更新:假设须要设置弹出窗体的宽度和高度,能够改动为以下的方法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string WindowName = "win" + System.DateTime.Now.Ticks.ToString();
Page.RegisterOnSubmitStatement("js", "window.open('','" + WindowName + "','width=600,height=200')");
form1.Target = WindowName;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://dotnet.aspx.cc");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body id="b" runat="server">
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="打开新窗体或者新 Tab " />
</form>
</body>
</html>
第二种弹出的方法能够參见老外的文章:
Response.Redirect 打开这两种方法的一种新形式的更多相关文章
- wordpress整站无损搬迁的几种方法 最后一种最完美
网站建设之wordpress整站无损搬迁的几种方法 最后一种最完美 网站搬家,当我们更换php虚拟主机,空间升级或更好空间提供商都会发生,站长们请注意,掌握网站迁移方法,是网站日常维护技术中必须掌握的 ...
- Response.Redirect 打开新窗体的两种方法
普通情况下,Response.Redirect 方法是在server端进行转向,因此,除非使用 Response.Write("<script>window.location=' ...
- Response.Redirect 打开新窗口的两种方法
一般情况下,Response.Redirect 方法是在服务器端进行转向,因此,除非使用 Response.Write("<script>window.location='htt ...
- Ajax跨域的几种方法以及每种方法的原理
js中几种实用的跨域方法原理详解 这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协 ...
- ubuntu12中设置PATH环境变量的几种方法(三种办法)
如果在Ubuntu12系统中自行安装了一些软件,特别是使用tar.gz文件包安装的软件,通常会放在/usr/local或者/opt,甚至放在/home下,但是如果要调用或执行时,必须加上完整的路径才可 ...
- Qt 设置背景图片3种方法(三种方法:QPalette调色板,paintEvent,QSS)
方法1. setStylSheet{"QDialog{background-image:url()"}} //使用styleSheet 这种方法的好处是继承它的dialog都会自 ...
- Java使用默认浏览器打开指定URL的方法(二种方法)
直接看代码:方法一: 复制代码 代码如下: Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://ww ...
- C#根据字体名通过注册表获取该字体文件路径(win10)两种方法推荐第二种
方法一: 直接先上源码: private System.Collections.Generic.SortedDictionary<string, string> ReadFontInfor ...
- ajax返回的值有两种方法,一种是把async:true改为false。 另一种是回调函数。
function load_val(callback){//定义一个回调函数 $.getJSON('test.php' , function(dat){ callback(data);//将返回结果当 ...
随机推荐
- 数据类型及其空间大小,vs2012实测
#include "stdafx.h" #include <stdio.h> #include "common.h" #include " ...
- jquery ajax调用返回json格式数据处理
Ajax请求默认的都是异步的 如果想同步 async设置为false就可以(默认是true) var html = $.ajax({ url: "some.php", async: ...
- CentOS6使用第三方yum源安装更多rpm软件包
引言: CentOS自带的yum源中rpm包数量有限,很多时候找不到我们需的软件包,(例如:要安装网络连接查看软件iftop,默认设置下无法使用yum命令安装),下面教大家在CentOS ...
- ecosphere是什么意思_ecosphere的翻译_音标_读音_用法_例句 - 必应 Bing 词典
ecosphere是什么意思_ecosphere的翻译_音标_读音_用法_例句 - 必应 Bing 词典 ecosphere
- PHP - 验证用户名
/** * * 函数名:_check_username($user_str,$min_num,$max_num); * 作用:检测用户名是否符合格式 * 参数: * 1:用户名 * 2:不得小于多少位 ...
- Eclipse用法和技巧二十二:快速调整字体大小
团队代码review的时候,一般都会一堆人围着显示器,或者投影仪.这个时候调整代码字体大小就显得很重要.下面直接说操作方式. 步骤一:Windows -> Preference 步 ...
- windows azure 实例
public class Album : TableServiceEntity { } public class PhotoAlbumDataContext : TableServiceContext ...
- Ultra Office Control 2.0
http://www.ultrashareware.com/Ultra-Office-Control.htm
- DELPHI语法基础学习笔记-Windows 句柄、回调函数、函数重载等(Delphi中很少需要直接使用句柄,因为句柄藏在窗体、 位图及其他Delphi 对象的内部)
函数重载重载的思想很简单:编译器允许你用同一名字定义多个函数或过程,只要它们所带的参数不同.实际上,编译器是通过检测参数来确定需要调用的例程.下面是从VCL 的数学单元(Math Unit)中摘录的一 ...
- javax.servlet.http.HttpServletRequest;
错误提示是没有引入javax.servlet.http.HttpServletRequest所在的包,编译错误. 这么添加: 项目-->右键-->properties-->java ...