Open New Tab/Window (Response.Redirect open in new web page)
Hello Friends,
Here I am going to explain how to open new tab/window on Button click using asp.net.
A week ago, i have to implement that code. I have option to use javascipt windows.open to open new tab.
But I have to insert or update some database entry. Yeah i know that there is another way to use clientscipt in code behind to achieve this.
But in its simplest form, following code open new tab/window.
<asp:Button ID=”btnNewEntry” runat=”Server” CssClass=”button” Text=”New Entry” OnClick=”btnNewEntry_Click” OnClientClick=”aspnetForm.target =’_blank’;”/>
<%– aspnetForm.target =’_blank’ will add handler to open new tab–%>
protected void btnNewEntry_Click(object sender, EventArgs e)
{
Response.Redirect(”New.aspx”);
}
OR
Response.Write( “<script> window.open( ‘pageName.aspx’ ); </script>”);
Response.End();
// Here we can write javascript code to open new tab
——————–
Happy programming.
32 Comments »
Leave a Reply
-
Archives
- April 2011 (1)
- May 2010 (1)
- April 2010 (1)
- February 2010 (3)
- January 2010 (5)
- December 2009 (6)
- November 2009 (13)
- October 2009 (10)
- September 2009 (6)
- August 2009 (7)
- July 2009 (7)
- June 2009 (3)
-
Categories
-
RSS
Entries RSS
Comments RSS
You will be redirected to the script in
seconds
Great! it is what I need!
what’s this,
OnClientClick=”aspnetForm.target =’_blank’
“aspnetForm” ??
is it the current form name or the new form?
yeah,its the current form name…
you will see this using view source from browser!
if i have my aspx form as “Add Problem.aspx” as and i want a link button in that form to ridirect me to “Previous Issues.aspx” page that needs to open in a new tab. how does it work.?
Previous Issues
this doesn’t work
Previous Issues
this is the code i used
this code is work perfectly…let me know what is the syntax you are using..?
—Previous Issues —–
add problem.aspx is the page am having the link label. i want to open previous issues.aspx in a new tab.
thanx for trying to help. :)
hey the code isnt attaching
runat=”server”
OnClientClick = “Previous Issues.target =’_blank’ ”
onclick=”lnkPrevious_Click1″>Previous Issues
asp:Button runat=”server” OnClientClick=”aspnetForm.target =’_blank’” OnClick=”lnkPrevious_Click1″
use above code to open in new tab..
u just need to specify the aspnetForm.Target instead of Previous Isses.Target!
why u people joking
Nothing is working.
Thanks Mr!
This is what I need!
cudn’t figure it out your way, bt i found another method.
Response.Write(“window.open(‘Assign Specialist.aspx’)”)
it worked out perfect for me. thanx for ur help :)
oops..script tag inside the double quotes missing
“i want to open previous issues.aspx in a new tab.”
You can out more?
For that follow the code above. u will redirect to previous page.
If not than find the previous url by using the request.referelurl
please find the solution for response.redirect in new window from t his post
http://myworkcodes.wordpress.com/2011/01/29/opening-new-window-using-response-redirect-in-asp-net/
Thanx For Such Very Good code.
but now problem is i just want to open a new tab on only one button click.
when i click any button on page all events are happening in new tab.
please help!!!!
Great Code at all..
Good work.
thanks, it works well
sir ,i want to open a new tab on button click event not new window.
plz help me…
Just use the code listed in this article.
Use the Firefox or other browser except the IE. IE will open new window instead of new tab. this is the default behavior in IE.
Thanks.. I was needed it.
IE default is always new window not tab. no workaround in IE?
but this code
OnClientClick=”aspnetForm.target =’_blank’;”
doesn’t work when i deploy my aplication at server & accessed at client machine.
I have used updatepanel.
plz reply ASAP?
Thanks & Regards.
Given first solution works only for first click, I have multiple links to open secondForm.aspx in new window. If I load Links.aspx & click on any random link it works perfectly, But not for the second click? no event is fired. Any clue?
Hi Shahid,
This code will work for every control on page. You just need to define the click events code..
Thanx it worked
the code to open page in new tab is working in local but not working on live site.
Is there any specific reason??
thnx a lots…it’s work
on first try i am unable to make it run because my Button is in update panel, but after that i got the way : i call PostBackTrigger to my button and it’s started working
Please let me know if you’re looking for a article author for your site. You have some really good articles and I feel I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine.
Please send me an e-mail if interested. Many thanks!
Hello, I think your site might be having browser compatibility issues.
When I look at your website in Chrome, it looks fine but when opening
in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that, amazing blog!