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 ...
随机推荐
- 搭建XMPP协议,实现自主推送消息到手机
关于服务器端向Android客户端的推送,主要有三种方式: 1.客户端定时去服务端取或者保持一个长Socket,从本质讲这个不叫推送,这是去服务端拽数据.但是实现简单,主要缺点:耗电等 2.Googl ...
- UML系列图------用例图介绍
UML-Unified Model Language 统一建模语言,又称标准建模语言.是用来对软件密集系统进行可视化建模的一种语言. 在UML系统开发中有三个主要的模型: 功能模型: 从用户的角度展示 ...
- APP测试时不可忽视搭建代理服务器抓包测试的必要性
这几天测的一个app,后台从已有服务器搬迁到了阿里云,接口api之类的都没有变化,但测试时发现客户端始终无法使用,每次点击都无法获得服务器反馈 用python编写脚本调接口,没问题,返回数据一切正常, ...
- eclipse手动导入dtd文件
1.在eclipse的工具栏上按照“Window->Preferences->XML->XML Catalog”依次点下去,然后在右侧选中 User Specified Entrie ...
- 游戏BI,起步了。
思索许久,终于决定自己的发展将会是游戏的BI. 即说即做,本文是我未来BI工作的开端. 传统的游戏BI,只是将运营的工作数据化,流量的变现指标化.和网站类似,无外乎用户导入,流失,保有,付费,回访等等 ...
- PHP强大的内置filter (一)
<?php #PHP内置的validate filter $input_data = True; $result = filter_var($input_data,FILTER_VALIDATE ...
- redhat 挂载 iso文件 提示 mount :not a directory
- oracle查看相关用户表
select TABLE_NAME from user_tables //当前用户表 select TABLE_NAME from dba_tables //所有用户表+系统表 select TA ...
- localStorage的一些简单的操作
本地存储 cookie localStorage cookie localStorage 生存周期 ...
- EntityFramwork6连接MySql错误
EntityFramwork6连接MySql错误 使用EF6连接MySql产生Exception: ProHub.ssdl(2,2) : 错误 0152: MySql.Data.MySqlClient ...