How to open a page in a new tab using an answer. redirect to asp.net

I want to open a new tab or new page by clicking the response.redirect button. im using a query string to pass some values. How to open a page in a new tab.

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 } 
+8
source share
8 answers

Try it. This works 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>"); } 
+7
source

You can change your design element as shown below: OnClientClick

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

Javascript Code:

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

The redirection is always on the same page from where you came from, you cannot open a new window from the redirection call.

I would suggest entering some javascript code in the client to open a new page upon reloading or to change a control that can be opened on a new page, for example LinkButton with the correct Target attribute.

+1
source

if you use http then use below code

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

this code cannot be used for https for https below

javascript on page

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

in c # code for

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

this code cannot block the browser popup blocker. the user must allow it to run. for example, it opens in a new window or in a new tab before the version in firefox and chrome opens a new tab

enjoy it!

+1
source

I ran into the same problem today.

Response.write did not work for me, to solve this problem I used System.Web.UI.ScriptManager.RegisterClientScriptBlock.

This is how the btnSave click event should be:

 protected void btnSave_Click(object sender, EventArgs e) { ...//some code to insert records System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openModal", "window.open('NewQuote.aspx?val= "+ this.txtQuotationNo.Text+"' ,'_blank');", true); } 

NOTE. I use ScriptManager.RegisterClientScriptBlock because the button is inside the UpdatePanel. If this is not your case, try:

 protected void btnSave_Click(object sender, EventArgs e) { ...//some code to insert records Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "openModal", "window.open('NewQuote.aspx?val= " + this.txtQuotationNo.Text + "' ,'_blank');", true); } 
+1
source

A simple solution here.

Edit the HTML button element and add the attribute OnClientClick = "target = '_ blank';".

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

Then at btnSave_Click

 Response.Redirect(url); 
0
source

Worked for me when I left double quotes outside the target value = '_ blank';

0
source

When it starts, I get this error

The value of the '__doPostBack' property is null or undefined, not a Function object

0
source

Source: https://habr.com/ru/post/1239422/


All Articles