Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 475 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to open page in new tab using the response. redirect at asp.net

#1
I want to open a new tab or a new page by using `Response.Redirect` in a button click handler. I'm using a query string to pass some values. How can I open he 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
}
```
Reply

#2
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.
Reply

#3
You can change your design element as 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>");
Reply

#4
if you are using http
then use below code


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


this code cannot be used for https
for https do below

javascript in page

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

in c# code behind




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

enjoy it!!
Reply

#5
Worked for me when I left the Double Quotes off of target ='_blank';
Reply

#6
I encountered this same problem today.

Response.write didn't work for me, to solve it I used instead System.Web.UI.ScriptManager.RegisterClientScriptBlock.

This is how your 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'm using ScriptManager.RegisterClientScriptBlock because the button is inside an UpdatePanel, if that's not your case you should 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);
}
Reply

#7
Simple solution is here.

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

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

Then in btnSave_Click

protected void btnSave_Click(object sender, EventArgs e) {
Response.Redirect(url);
}

Reply

#8
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>");
}
```
Reply

#9
You can use ScriptManager to do the needed:

private void Redirect_New_Tab(string url_To_Open)
{
string modified_URL = "window.open('" + url_To_Open + "', '_blank');";
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", modified_URL , true);
}
Reply

#10
Response.write didn't work for me, so I used instead System.Web.UI.ScriptManager.RegisterClientScriptBlock.

System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openModal", "window.open('NewQuote.aspx?val= "+ this.txtQuotationNo.Text+"' ,'_blank');", true);
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through