6

We are using ASP.NET Webforms (not MVC).

My question is this: Is it possible to open a new browser window using a postback and then some variety of Response.Redirect?

  • 1
    Have you tried any thing ? – Ajay Aug 07 '13 at 04:49
  • Response.Redirect cannot open a browser as Response.Redirect is Server side command, and browser doesn't exists on server. You need to throw a javascript code to open a new window as @JLC007 suggest in it's answer. – Sumit Gupta Aug 07 '13 at 04:54

3 Answers3

7

I have not come across instances where Response.Redirect can navigate opening a new window.

Here are a way of doing it not using Response.Redirect which you can try:

ScriptManager.RegisterStartupScript(this, typeof(string), "New_Window", "window.open( 'http://www.website.com', null, 'height=800,width=1280,status=yes,toolbar=yes,menubar=yes,location=no' );", true);
Conrad Lotz
  • 8,200
  • 3
  • 23
  • 27
  • You can add `'_blank'` in place of the `null` but I tested it and both give the same result. It opens a new window. – Conrad Lotz Aug 07 '13 at 06:34
  • Note that browsers may treat scripts that run on page load in this manner as being page-initiated, rather than user-initiated. Such links may be blocked by popup-blockers. – Brian Mar 01 '18 at 16:20
1

Short answer? No.

Long answer:

ASP.NET is a server side framework, whereas the concept of browser windows is a client side one. Response.Redirect just ends up sending a Location: [whatever the new url is] header as part of the output stream. It just happens that pretty much all browsers handle that header by loading up the url that's in that header.

The most pain-free way would be using javascript on the postback to open the new window, as outlined in JLC007's answer. Another possible option is using the target attribute on the rendered form.

Community
  • 1
  • 1
rossipedia
  • 56,800
  • 10
  • 90
  • 93
  • I suppose "shortly" is relative, but when is the longer answer coming? – Patrick Aug 07 '13 at 05:39
  • Just now. Got sidetracked. – rossipedia Aug 07 '13 at 05:45
  • I would probably use another source when linking to target, namely [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target). Even though w3schools often has valid information, there's the question of quality (http://www.w3fools.com/). – Patrick Aug 07 '13 at 05:56
  • Thx for the tip, didn't realize they weren't W3C affiliated. – rossipedia Aug 07 '13 at 06:00
1

Try this

 ScriptManager.RegisterStartupScript(this, typeof(string), "openWindow", 
     "window.open( 'http://www.website.com', target="_blank", 
     'height=800,width=1280,status=yes,toolbar=yes,menubar=yes,location=no' );",
       true);
Amit
  • 15,217
  • 8
  • 46
  • 68