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 打开新窗体的两种方法的更多相关文章
- Response.Redirect 打开新窗口的两种方法
一般情况下,Response.Redirect 方法是在服务器端进行转向,因此,除非使用 Response.Write("<script>window.location='htt ...
- DataGridView动态添加新行的两种方法
简单介绍如何为DataGridView控件动态添加新行的两种方 法: 方法一: int index=this.dataGridView1.Rows.Add();this.dataGridView1.R ...
- windows 7中添加新硬件的两种方法(本地回环网卡)
最近在windows7上使用VMwareWorkstation7玩一些实验,遇到需要配置不同网络的问题. 因为在windows2003server上习惯使用要本地回环网卡了,那就想着在Windows7 ...
- Android驱动学习-APP操作新硬件的两种方法(支持添加的驱动)
在给Android添加新的驱动后,app要如何使用呢? 正常的使用一个设备,需要getService.但是像LED等我们自己添加的硬件驱动,Android源代码根本没有我们自己添加的服务. 第一种: ...
- js打开新窗口的两种方式
1.超链接<a href="http://www.jb51.net" title="脚本之家">Welcome</a>等效于js代码wi ...
- node服务器中打开html文件的两种方法
方法1:利用 Express 托管静态文件,详情查看这里 方法2:使用fs模块提供的readFile方法打开文件,让其以text/html的形式输出. 代码: var express = requir ...
- Android 进入另外一个窗体的两种方法
方法一: Intent intent = new Intent(); intent.setClassName(this, "com.wuyou.twoactivity.OtherActivi ...
- PHP如何通过URL访问,获得新的URL 两种方法
1.1 $url = 'http://passport.drcloud.cn/api/logon.asp?id=1&ru=http://203.158.158.122/store/thirdL ...
- Response.Redirect 打开这两种方法的一种新形式
在一般情况下.Response.Redirect 该方法是在server年底转向,因此,除非 Response.Write("<script>window.location='h ...
随机推荐
- JavaScript/jQuery 表单美化插件小结
Niceforms Niceforms是一款独立的表单美化工具,当前版本为2.0 官方主页:http://www.emblematiq.com/lab/niceforms/ 官方演示:http://w ...
- ASP.NET转换人民币大小金额
public class DecimalToRMB { /// <summary> /// 转换人民币大小金额 /// </sum ...
- 【Linux】一个简单的线程创建和同步的例子
最近很多精力在Linux上,今天简单看了一下Linux上的线程和同步,其实不管windows还是Linux,OS层面的很多原理和概念都是相同的,很多windows之上的经验和概念完全可以移植到Linu ...
- Android百度地图开发(一)环境搭建
1.百度地图官方API文档下载 版本 使用说明 下载 Android SDK 通用资源下载 <离线地图>提供新版离线地图(百度矢量地图)与旧版离线地图(百度栅格地图)下载. 备注: 自An ...
- js中ajax如何解决跨域请求
js中ajax如何解决跨域请求,在讲这个问题之前先解释几个名词 1.跨域请求 所有的浏览器都是同源策略,这个策略能保证页面脚本资源和cookie安全 ,浏览器隔离了来自不同源的请求,防上跨域不安全的操 ...
- HTML的<head>中的内容总结
[01]文件头部一般包含标题标签.<meta>标签.内联样式表及预定义脚本等. [02]<meta>标签在网页内容中不显示,但它的作用不容忽视.<meta>标签主要 ...
- vim 7.4 编译安装
(1): 在安装新版本的Vim之前,你需要卸载原来安装的老版本Vim,依次在终端下执行下列命令: sudo apt-get remove vim sudo apt-get remove vim-run ...
- dedecms list 判断 每隔3次输出内容
{dede:list pagesize='12' runphp='yes'} [field:global name=autoindex runphp="yes"](@me%3==0 ...
- IOS 异步加载图片
#import <Foundation/Foundation.h> #import "StringUtils.h" @interface ImageManager : ...
- 一个采用python获取股票数据的开源库,相当全,及一些量化投资策略库
tushare: http://tushare.waditu.com/index.html 为什么是Python? 就跟javascript在web领域无可撼动的地位一样,Python也已经在金融量化 ...