1

I am using gridview to display the booking history when the user clicks on a "print" button. A printticket.aspx page should open in a new window. I have used window.open but it is blocked by the browser.

   string url = "../Printticket.aspx";
   string fullURL = "window.open('" + url + "', '_blank', 'height=600,width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no' );";
    ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);

I want to open the printticket page in a new window. Is there any other way?

Tajkumar
  • 317
  • 2
  • 5
  • 16
  • Why not just a regular ` – millimoose Jan 30 '14 at 01:14
  • i have to do some code behind work like assigning session value that is why am asking to open new window from code behind – Tajkumar Jan 30 '14 at 01:52
  • Can you do that codebehind work when `Printticket.aspx` is loaded instead? Generally pushing JS for the browser to execute as the result of an AJAX call makes me uncomfortable. (One reason why is the one you just discovered – it's hard to tell what happened when something goes wrong since the reason is buried who knows where in the machinery used to support this.) – millimoose Jan 30 '14 at 03:17
  • To put it another way: seeing how many webapps make do without `window.open()`, I don't think you **have to** do that code-behind work exactly between the link being clicked and the popup window opening. (As opposed to shortly after the popup window opens.) – millimoose Jan 30 '14 at 03:21
  • I WILL ASSIGN the session value to ticketid and it is used by the printticket .aspx to load the values in that page – Tajkumar Jan 30 '14 at 03:37
  • is there any way like to load onclientclick and oncommand event at a time – Tajkumar Jan 30 '14 at 03:39
  • 1
    Moving this via a session is a silly design to begin with. Use a query parameter. I.e. make a link to `PrintTicket.aspx?ticketid=123`, and on the other side, read it with [`Request.QueryString["ticketid"]`](http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring(v=vs.110).aspx). I'd also suggest poking a little at how web applications work without ASP.NET mechanisms confusing things. ASP.NETisms are good at pretending you can make changes to a stateful page. To communicate between pages it's better to "drop down" to lower-level constructs. – millimoose Jan 30 '14 at 03:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46395/discussion-between-tajkumar-and-millimoose) – Tajkumar Jan 30 '14 at 03:44

1 Answers1

1

I had the same problem and have managed to resolve it.

This solutions works for both ASP:Button and ASP:LinkButton.

string url = "../Printticket.aspx";
string fullURL = "window.open('" + url + "', '_blank', 'height=600,width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no' );";
btnButton.OnClientClick = fullURL;

Where btnButton is typeof(Button) or typeof(LinkButton)

Hope this helps someone later.

RealSollyM
  • 1,530
  • 1
  • 22
  • 35