可以在新窗口中打开response.redirect吗? [英] Can response.redirect open in new windows?

查看:64
本文介绍了可以在新窗口中打开response.redirect吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 它是我的代码:

Hi its my code:

<asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False"

                    CellPadding="4" ForeColor="#333333" GridLines="None"

                onrowcommand="GridView1_RowCommand">
                    <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <Columns>
                     <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                          <asp:LinkButton ID="LinkButton1" runat="server"

                          Text='<%# Eval("titr") %>' CommandArgument='<%# Eval("filename")%>'

                           CommandName="file">
                           </asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    </Columns>
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                </asp:GridView>





protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       string nid = e.CommandArgument.ToString();
       if (e.CommandName == "file")
       {
            Response.Redirect("~/upload/" + nid);

       }
   }


我需要在新窗口中打开此URL,但似乎不可能,是否有任何方法可以在新窗口中打开此URL?


I need to open this url in new window but seems its impossible, is there any way to open this url in new window?
thanks in advance.

推荐答案

我需要在新窗口中打开该URL,但似乎不可能,有什么办法在新窗口中打开该URL?
是的你可以.使用Response.Write或Response.Redirect打开新窗口.

在这里看看:
C#ASP.NET响应.重定向到新窗口中 [ ^ ]
类似的线程正在讨论相同内容 [
I need to open this url in new window but seems its impossible, is there any way to open this url in new window?
Yes, you can. Using Response.Write or Response.Redirect to open a new window.

Have a look here:
C# ASP.NET Response.Redirect Open Into New Window[^]
Similar thread discussing the same[^]


UPDATE:
As OP asked, copy-pasting one of the stuff from 1st link:
So I came across the day the desire to have a button open up a new window instead of just using an anchor tag, as usual I run the idea through google and mostly come back with responses saying it’s not possible that way, or to add javascript to the page to capture events. Not quite the solution I was looking for after doing some more searching I came across a javascript solution that would work but wasn’t elegant at all which led me to ponder on adapting it to be cleaner and this is what I came up with:
<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="btnNewEntry_Click" OnClientClick="aspnetForm.target ='_blank';"/>

protected void btnNewEntry_Click(object sender, EventArgs e)
{
    Response.Redirect("New.aspx");
}


它甚至可以使用Server.Transfer来工作.在那里,您可以使用一个简单的解决方案来处理Response.Redirect,无需添加任何javascript标记即可重定向到新窗口,而只需利用按钮本身的OnClientClick事件即可.

如果您在单个页面上有多个按钮,并且只希望将特定按钮启动到新窗口中,并希望其余按钮保留在当前表单上,请确保您装饰其他按钮,如


It even works using Server.Transfer. There you have it a simple unobtrusive solution to handle Response.Redirect into a new window without needing to add any javascript tags and only take advantage of the OnClientClick event on the button itself.

If you have multiple buttons on a single page and only want a specific button to launch into a new windows and want the rest to stay on the current form make sure you decorate your other buttons like

<asp:Button ID="btnStayOnPage" runat="Server" CssClass="button" Text="Stay here" OnClick="btnStayOnPage_Click" OnClientClick="aspnetForm.target ='_self';"/>

protected void btnStayOnPage_Click(object sender, EventArgs e)
{
   //Do normal code for postback

}


这篇关于可以在新窗口中打开response.redirect吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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