Problem with opening new window "window.Open" using javascript

I am trying to open new window when press a button "btnPrint" using:

Response.Write("<script language='javascript'> window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes'); </script>");

but when the new window opened the current page do a post back action and the current page format change like the following:

before window open:

after window opened:

So, how i can a void the post back action. 

0
BigSmile
1/28/2008 10:47:27 AM
asp.net.client-side 24353 articles. 1 followers. Follow

9 Replies
4206 Views

Similar Articles

[PageSpeed] 20

<script language='javascript'> function Call(window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes');  return false)</script>

 

in aspx page add this javascript under the head tag

after that

in btnPrint add this attribute onClientClick ="javascript:return Call()"

 


We Are Looking for .NET/PHP Projects

Contact Details :-

 Email - sameer.khanjit@gmail.com

 Mobile no. : +91-9893795983

 View Blog

linkedin Asp.net Group

Don't forget to click “Mark as Answer” on the post that helped you
0
sameer_khanjit
1/28/2008 11:13:27 AM

BigSmile:

I am trying to open new window when press a button "btnPrint" using:

Response.Write("<script language='javascript'> window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes'); </script>");

but when the new window opened the current page do a post back action and the current page format change like the following:

Well offcourse the Button will post back by nature. What you can do is create a javascript function somthing like this.

<script language="javascript">
function ShowPopup()
{
      window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes');
}
</script>

now you your code file write this on the form's load event

if !(IsPostBack)
{
     btnPrint.Attributes.Add("OnClientClick", "javascript:ShowPopup()");
}

Hope it will solve your problem.


Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
0
farazsk11
1/28/2008 11:14:06 AM

BigSmile:
Response.Write("<script language='javascript'> window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes'); </script>");

instead of using Response.Write you can write in page_load as...

//on click of button3... open the coupon report 

Button3.Attributes.Add("onclick","javascript:window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes'); return false;"); 

"return false" would not cause a post back on the parent page...

 

hope it helps./. 


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
1/28/2008 11:16:08 AM

Either the KaushaL or sameer_khanjit solutions will work. The farazsk11 solution will still cause a PostBack on an ASP:Button. The simplest and neatest solution is KaushaL's. I would definitely use that one!

Also, NEVER use Response.Write to output to an ASP.NET page. Use RegisterStartupScript (for in-line script) or RegisterClientScriptBlock (for functions). Response.Write puts the output above the page tags which interferes with the page rendering correctly. Response.Write should ONLY be used for developmental debugging situations.

NC...

0
NC01
1/28/2008 1:10:47 PM

NC01:

Either the KaushaL or sameer_khanjit solutions will work. The farazsk11 solution will still cause a PostBack on an ASP:Button. The simplest and neatest solution is KaushaL's. I would definitely use that one!



Very true... "return false" is missing in my post which will cause post back. You should go either of the other 2 solutions. I would also prefer Kaushal's post.


Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
0
farazsk11
1/29/2008 8:29:16 AM

I write Response.Write statement in button click event so when i press the button "btnPrint" the statement will execute and redirect to different pages according to DropDownList selected value like:

Response.Write("<script language='javascript'> window.open('"+ DropDownList1.SelectedValue +

"', 'window','HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes');</script>");

 

0
BigSmile
1/30/2008 6:32:47 AM

BigSmile:
I write Response.Write statement in button click event so when i press the button "btnPrint" the statement will execute and redirect to different pages according to DropDownList selected value like:
 

did you check out the post by NC01..?

NC01:

Also, NEVER use Response.Write to output to an ASP.NET page. Use RegisterStartupScript (for in-line script) or RegisterClientScriptBlock (for functions). Response.Write puts the output above the page tags which interferes with the page rendering correctly. Response.Write should ONLY be used for developmental debugging situations.

 

 



Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
1/30/2008 8:40:52 AM

KaushaL,

I don't know how else to put that to get even more forceful! Using Response.Write to render JavaScript is probably the cause of 25% of the problems posted here.

NC...

0
NC01
1/30/2008 2:04:58 PM

NC01:
I don't know how else to put that to get even more forceful! Using Response.Write to render JavaScript is probably the cause of 25% of the problems posted here.
 

i agree./.


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
1/30/2008 2:45:20 PM
Reply:

Similar Artilces:

"Open", "Open in new window", "Open in new tab" are greyed-out after drag&drop operation
Name: Dmitriy Email: dadotivanovathotmaildotcom Product: Firefox Release Candidate Summary: "Open", "Open in new window", "Open in new tab" are greyed-out after drag&drop operation Comments: Steps to Reproduce: 1. Drag&drop a bookmark from the Bookmarks Menu or Bookmarks Toolbar to the Tab bar. 2. Right-click on any bookmark (from the same folder, if darged from Menu, or from the visible part of Bookmarks Toolbar) Result: "Open", "Open in new window", "Open in new tab" are greyed-out Browser Details: Moz...

"Move tab to new window" is wanted; "Open in new window" is faulty.
Name: Michael Email: keybounceatgmaildotcom Product: Firefox Summary: "Move tab to new window" is wanted; "Open in new window" is faulty. Comments: Right now, tabs in FF 3.5.2 have "Open in new window". What they need is "Move tab to new window". The problem? The page is fully reloaded from scratch. Not all pages can be reloaded. Even if it doesn't look like a PUT, not all GETs return the same page. Even when they do, it may result in a lot of re-processing of javascript, etc. From URL: http://hendrix.mozilla.org/ Note to ...

shifting "open in new tab" and "open in new window" in firefox 2
Name: Markus Gr�rmann Email: randale-mail_at_gmx.de Product: Firefox Summary: shifting "open in new tab" and "open in new window" in firefox 2 Comments: Heyho! In firefox 2, opening new pages in a new tab instead of a new window is the standard setting. But ifyou right-click on a random link to open it either in a new window or a new tab, the option on top of the right-click-menu is "open in new window" you have to scroll down to open the link in a new tab. To support tabbed browsing as well as possible, the option to open links in a new tab s...

new window open FTP but don't wanna use Button1.Attributes.Add("onclick", "javascript")
hi all,i wanna open a FTP in a new windowi use :Button1.Attributes.Add("onclick", "var varOpenWin = window.open('" + pstrNewFTP + _  "' ,'FTU', 'width=700,height=500,copyhistory=no,directories=no,titlebar=no," + _  "properties=no,menubar=no,toolbar=yes,location=no,scrollbars=yes," + _  "resizable=yes,status=no');")it works, but actually i have to check the password (system login & pwd not the FTP password)so i think i can't use Button1.Attributes.Add (under page load function)anyone kno...

"new tab" should create a new window if there is no open window.
Name: Adam Kramer Email: adik-mozillaatilovebacondotorg Product: Firefox Release Candidate Summary: "new tab" should create a new window if there is no open window. Comments: ....that's it...I just keep hitting command-T and then having to command-N. Browser Details: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5 From URL: http://hendrix.mozilla.org/ ...

superreview cancelled: [Bug 241972] new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins : [Attachment 225294] close blank window
Marria Nazif <marria@gmail.com> has cancelled Marria Nazif <marria@gmail.com>'s request for superreview: Bug 241972: new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins https://bugzilla.mozilla.org/show_bug.cgi?id=241972 Attachment 225294: close blank window https://bugzilla.mozilla.org/attachment.cgi?id=225294&action=edit ...

superreview requested: [Bug 241972] new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins : [Attachment 225294] close blank window
Marria Nazif <marria@gmail.com> has asked Darin Fisher (Google) <darin@meer.net> for superreview: Bug 241972: new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins https://bugzilla.mozilla.org/show_bug.cgi?id=241972 Attachment 225294: close blank window https://bugzilla.mozilla.org/attachment.cgi?id=225294&action=edit ------- Additional Comments from Marria Nazif <marria@gmail.com> This is a first try at closing the window after the external app handler has done its work. This se...

I am using a client side javascript to open a new window and have a problem
I have a user control..On it i have the word 'open' as a link....calling my javascript to open another page.....This page then auto close with javascript...Problem is when you click on 'open' it brings up my page and another page about:blank.......how do you avoid this???? hello, u would like to check my article on the following address: Pop Up Window from inside ASP.NET best of luck.Bilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

superreview requested: [Bug 275430] change "open links from other applications" to be "a new tab in the most recent window" instead of "the most recent tab/window" : [Attachment 177848] Patch to make
Jeremy Morton <bugzilla@game-point.net> has asked Ben Goodger <bugs@bengoodger.com> for superreview: Bug 275430: change "open links from other applications" to be "a new tab in the most recent window" instead of "the most recent tab/window" https://bugzilla.mozilla.org/show_bug.cgi?id=275430 Attachment 177848: Patch to make externally-launched links open in new window https://bugzilla.mozilla.org/attachment.cgi?id=177848&action=edit ...

superreview cancelled: [Bug 275430] change "open links from other applications" to be "a new tab in the most recent window" instead of "the most recent tab/window" : [Attachment 177848] Patch to make
Mike Connor <mconnor@steelgryphon.com> has cancelled Jeremy Morton <bugzilla@game-point.net>'s request for superreview: Bug 275430: change "open links from other applications" to be "a new tab in the most recent window" instead of "the most recent tab/window" https://bugzilla.mozilla.org/show_bug.cgi?id=275430 Attachment 177848: Patch to make externally-launched links open in new window https://bugzilla.mozilla.org/attachment.cgi?id=177848&action=edit ------- Additional Comments from Mike Connor <mconnor@steelgryphon.com> New ...

New tab to opening instead of window when "New Window" option set
Name: Trevor Lohrbeer Email: trevordotlohrbeeratgmaildotcom Product: Firefox Release Candidate Summary: New tab to opening instead of window when "New Window" option set Comments: Clicking a link with target="_blank" causes a new tab to open instead of a window, even when the "New pages should be opened in" setting under Tools > Options > Tabs is set to "New window" Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b4) Gecko/2008030714 Firefox/3.0b4 From URL: http://hendrix.mozilla.org/ ...

Without using Javascript "window.open", Is it possible to show a popup window without address bar, menu bar etc?
 Without using Javascript "window.open", Is it possible to show a popup window without address bar, menu bar & also with IE page size etc? I want to do it without using html/dhtml controls. Using Javascript is the only way to open a true browser window.You can use DHTML (with Javascript) to open a div that can be styled to look like a window, but it will be placed within the page (although you can visually make it appear on top of the page).If this post was useful to you, please mark it as answer. Thank you!...

Bug 241972 new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins
Bug 241972 new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins This bug is filed against Firefox but aren't all these files under core? <https://bugzilla.mozilla.org/attachment.cgi?id=227973&action=view> DocShell, WebNavigation, WindowWatcher, etc. Will this patch be picked up by SeaMonkey trunk? Phil -- Philip Chee <philip@aleytys.pc.my>, <philip.chee@gmail.com> http://flashblock.mozdev.org/ http://xsidebar.mozdev.org Guard us from the she-wolf and the wolf, and guard ...

How to close all windows that open with command "open" except the first window?
Hi, I build an application with login and users manager. After validate login, the user can open different windows (opensheet & open). My problem appears when this user use my logoff : I can easly close all sheets but I can�t close the window that open with the command "open(...)". Are there a command (or other) to obtain the open window? Maybe that do I must work with a window�s array? What do you think? All solutions are welcome! Thanx in advance Chris M. Generally speaking, the parent of windows opened with Open() is the MDI frame, so if you...

Web resources about - Problem with opening new window "window.Open" using javascript - asp.net.client-side

Resources last updated: 1/17/2016 7:31:12 AM