如何使用响应在新选项卡中打开页面。在asp.net重定向

时间:2022-10-07 08:49:50

i want to open new tab or new page by using response.redirect in button click. im using query string to pass some values.so how to open page in new tab .

我想在按钮单击中使用response.redirect打开新选项卡或新页面。即时通讯使用查询字符串传递一些值。所以如何在新选项卡中打开页面。

protected void btnSave_Click(object sender, EventArgs e)
   {
     ...//some code to insert records
 Response.Redirect("NewQuote.aspx?val=" + this.txtQuotationNo.Text);//displaying gridview in other page to print what needed

}

5 个解决方案

#1


6  

Try this. This works sure for me...

尝试这个。这对我有用......

protected void btnSave_Click(object sender, EventArgs e)
   {
     ...//some code to insert records
 Response.Write("<script>window.open ('NewQuote.aspx?val=" + txtQuotationNo.Text+"','_blank');</script>");


}

#2


3  

You can change your design element as below : OnClientClick

您可以按如下方式更改设计元素:OnClientClick

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"  OnClientClick ="document.forms[0].target = '_blank';"  />

Javascript code :

Javascript代码:

 Response.Write("<script>");
 Response.Write("window.open('NewQuote.aspx' ,'_blank')");
 Response.Write("</script>");

#3


1  

A redirect is always in the same page as where you came from, you can't open a new window from a redirect call.

重定向始终与您来自的位置在同一页面中,您无法通过重定向调用打开新窗口。

I would suggest to inject some javascript code in the client to open the new page on reload, or change to a control that can open to a new page, like a LinkButton with the right Target attribute.

我建议在客户端注入一些javascript代码以在重新加载时打开新页面,或者更改为可以打开到新页面的控件,例如具有正确Target属性的LinkBut​​ton。

#4


1  

if you are using http then use below code

如果您使用的是http,请使用下面的代码

Response.Write("<script>window.open ('URL','_blank');</script>");

this code cannot be used for https for https do below

此代码不能用于以下https的https

javascript in page

页面中的javascript

function shwwindow(myurl) {
    window.open(myurl, '_blank');
}

in c# code behind

在c#代码后面

 string URL = ResolveClientUrl("~") + "**internal page path**";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "show window", 
    "shwwindow('"+URL+"');", true);

this code cannot bybass the browser popup blocker. user must allow it to run. for ie it opens in new window or new tab up to ie version in firefox and chrome it opens new tab

此代码无法通过浏览器弹出窗口阻止程序。用户必须允许它运行。因为它在新窗口或新标签中打开,即firefox和chrome中的版本,它会打开新标签

enjoy it!!

#5


0  

Simple solution is here.

这里简单的解决方案。

Edit your html button element and add attribute OnClientClick="target ='_blank';".

编辑html按钮元素并添加属性OnClientClick =“target ='_ blank';”。

<asp:Button ID="myButton" runat="server" CssClass="btn1"
            OnClick="btnSave_Click" OnClientClick="target ='_blank';" />

Then in btnSave_Click

然后在btnSave_Click中

Response.Redirect(url);

#1


6  

Try this. This works sure for me...

尝试这个。这对我有用......

protected void btnSave_Click(object sender, EventArgs e)
   {
     ...//some code to insert records
 Response.Write("<script>window.open ('NewQuote.aspx?val=" + txtQuotationNo.Text+"','_blank');</script>");


}

#2


3  

You can change your design element as below : OnClientClick

您可以按如下方式更改设计元素:OnClientClick

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"  OnClientClick ="document.forms[0].target = '_blank';"  />

Javascript code :

Javascript代码:

 Response.Write("<script>");
 Response.Write("window.open('NewQuote.aspx' ,'_blank')");
 Response.Write("</script>");

#3


1  

A redirect is always in the same page as where you came from, you can't open a new window from a redirect call.

重定向始终与您来自的位置在同一页面中,您无法通过重定向调用打开新窗口。

I would suggest to inject some javascript code in the client to open the new page on reload, or change to a control that can open to a new page, like a LinkButton with the right Target attribute.

我建议在客户端注入一些javascript代码以在重新加载时打开新页面,或者更改为可以打开到新页面的控件,例如具有正确Target属性的LinkBut​​ton。

#4


1  

if you are using http then use below code

如果您使用的是http,请使用下面的代码

Response.Write("<script>window.open ('URL','_blank');</script>");

this code cannot be used for https for https do below

此代码不能用于以下https的https

javascript in page

页面中的javascript

function shwwindow(myurl) {
    window.open(myurl, '_blank');
}

in c# code behind

在c#代码后面

 string URL = ResolveClientUrl("~") + "**internal page path**";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "show window", 
    "shwwindow('"+URL+"');", true);

this code cannot bybass the browser popup blocker. user must allow it to run. for ie it opens in new window or new tab up to ie version in firefox and chrome it opens new tab

此代码无法通过浏览器弹出窗口阻止程序。用户必须允许它运行。因为它在新窗口或新标签中打开,即firefox和chrome中的版本,它会打开新标签

enjoy it!!

#5


0  

Simple solution is here.

这里简单的解决方案。

Edit your html button element and add attribute OnClientClick="target ='_blank';".

编辑html按钮元素并添加属性OnClientClick =“target ='_ blank';”。

<asp:Button ID="myButton" runat="server" CssClass="btn1"
            OnClick="btnSave_Click" OnClientClick="target ='_blank';" />

Then in btnSave_Click

然后在btnSave_Click中

Response.Redirect(url);