在新标签页或窗口中重定向 [英] redirect in new tab or window

查看:102
本文介绍了在新标签页或窗口中重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在新窗口中重定向页面但是无法执行此操作

说明 - 我有gridview其中我已经按下了按钮字段,点击此按钮下载指定行将开始,然后我编码responce.redirect这个文件,但我想在新的选项卡或窗口,所以PLZ告诉我它是如何设置的



 <   asp:GridView    < span class =code-attribute> ID   =  GridView1    runat   = 服务器  

AutoGenerateColumns = False

DataSourceID = SqlDataSource3

onrowcommand = GridView1_RowCommand

< span class =code-attribute> DataKeyNames = DocID

< span class =code-attribute> 高度 = 50px 宽度 = 50px AllowSorting = True >
< >
< asp: BoundField DataField = DocID HeaderText = DocID

InsertVisible = False

ReadOnly = True

SortExpression = DocID 可见 = 错误 / > < asp:ButtonField ButtonType = 图片

< span class =code-attribute> ImageUrl = 〜/ download-button.jpg

CommandName = 下载

HeaderText = 下载 ControlStyle -Height = 20px

ControlStyle-Width = 20px >
< ControlStyle 高度 = 20px 宽度 = 20px > < / ControlStyle >
< / asp:ButtonField >
< /列 >
< / asp:GridView >



和cs页面





<前lang =cs> 受保护 void GridView2_RowCommand( object sender,GridViewCommandEventArgs e)
{
if (e.CommandName == 下载
{
string fileName = string .Empty;
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView2.Rows [index];
int documentID = Convert.ToInt32(GridView2.DataKeys [index] .Value);
SqlConnection con = new SqlConnection( Server =。; Database = E_Notes; integrated Security = true);
// SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ConnectionString]。ConnectionString);
SqlCommand cmd = new SqlCommand( SELECT DocName FROM SaveDoc WHERE DocID = + documentID,con);
con.Open();
SqlDataReader dReader = cmd.ExecuteReader();
while (dReader.Read())
{
fileName = dReader [ DocName]。ToString();
byte [] documentBinary =( byte [])dReader [ DocData];
FileStream fStream = new FileStream(Server.MapPath( ../ Docs /)+ @ \ + fileName ,FileMode.Create);
fStream.Write(documentBinary, 0 ,documentBinary.Length);
fStream.Close();
fStream.Dispose();
}
con.Close();
Response.Redirect( @ .. \Docs \ + fileName);
}
}

已添加代码块[/ Edit]

解决方案





看看这里:

http:/ /stackoverflow.com/a/8994342 [ ^ ]

你不能是简短的答案。浏览器是唯一可以打开一个新窗口的东西。



您可以做的是在响应中发送一大块html,其中包含与您网址的链接作为一个href,target =_ blank和一个伪造点击的表单的javascript onload。如果这不起作用则使用window.open(url);

 response.write( < script>); 
response.write( window.open('page.html','_ blank'));
response.write( < / script>);




I want to redirect a page in new window but not able to do this
explanation-i have gridview in which i have taken button field,on click of this button the downloading of the specified row will starts and after that i code responce.redirect this document but i want in new tab or window so plz tell me how it is posible

<asp:GridView ID="GridView1" runat="server"

              AutoGenerateColumns="False"

              DataSourceID="SqlDataSource3"

              onrowcommand="GridView1_RowCommand"

              DataKeyNames="DocID"

                            Height="50px" Width="50px" AllowSorting="True">
<Columns>
<asp:BoundField DataField="DocID" HeaderText="DocID"

                InsertVisible="False"

                ReadOnly="True"

                SortExpression="DocID" Visible="False" /><asp:ButtonField ButtonType="Image"

               ImageUrl="~/download-button.jpg"

               CommandName="Download"

               HeaderText="Download" ControlStyle-Height="20px"

       ControlStyle-Width="20px" >
                               <ControlStyle Height="20px" Width="20px"></ControlStyle>
                               </asp:ButtonField>
                           </Columns>
                       </asp:GridView>


and on cs page


protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "Download")
       {
           string fileName = string.Empty;
           int index = Convert.ToInt32(e.CommandArgument);
           GridViewRow row = GridView2.Rows[index];
           int documentID = Convert.ToInt32(GridView2.DataKeys[index].Value);
           SqlConnection con = new SqlConnection("Server=.;Database=E_Notes;integrated Security=true");
           //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
           SqlCommand cmd = new SqlCommand("SELECT DocName FROM SaveDoc WHERE DocID = " + documentID, con);
           con.Open();
           SqlDataReader dReader = cmd.ExecuteReader();
           while (dReader.Read())
           {
               fileName = dReader["DocName"].ToString();
               byte[] documentBinary = (byte[])dReader["DocData"];
               FileStream fStream = new FileStream(Server.MapPath("../Docs/") + @"\" + fileName, FileMode.Create);
               fStream.Write(documentBinary, 0, documentBinary.Length);
               fStream.Close();
               fStream.Dispose();
           }
           con.Close();
           Response.Redirect(@"..\Docs\" + fileName);
       }
   }

[Edit]Code block added[/Edit]

解决方案

Hi,

Have a look here:
http://stackoverflow.com/a/8994342[^]

You can''t is the short answer. The browser is the only thing that can open up a new window.

What you can do is send a chunk of html down the response that has a link with your url as an href, target="_blank" and a chunk of javascript onload of the form that fakes a click. If this doesn''t work then use a window.open(url);

response.write("<script>");
response.write("window.open('page.html','_blank')");
response.write("</script>"); 



这篇关于在新标签页或窗口中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆