Solved

Open New Window from ASP.Net control and specify dimensions

Posted on 2003-11-04
11
200,081 Views
Last Modified: 2011-08-18
  I have an aspx form from which I would like to pop up a new window. I can do that using an ASP.Net hyperlink control with the Target value set to "_blank". How can I control the dimensions of the new window? I would like it to be quite a bit smaller than the main window.
   I have seen various solutions poking around on Google, but I'm wondering if there is a very simple solution that works within the ASP.Net control.
   Thanks, ted
0
Comment
Question by:tk3
11 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 9686392
you can use <asp:hyperlink target=_blank>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 9686466
Use this javascript function
<script language="JavaScript">

<!--//

function new_window(url) {

link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=500,left=40,top=50");

}
//-->
</script>
 then you can either use a button to open it

btnOpen.Attributes.Add ("onClick", "new_window('test.aspx')")

or hyperlink

<asp:HyperLink id="lnkOpen" runat="server">Open</asp:HyperLink
lnkOpen.Attributes.Add("onClick", "new_window('test.aspx')")
0
 

Author Comment

by:tk3
ID: 9689625
  I came up with this solution, which I think is what I was looking for.
   In the NavigateURL property of an asp:HyperLink, I put the string:
javascript:var w=window.open('TestPage.aspx','', 'width=625,height=760,scrollbars=yes,resizeable=yes');

   This seems to me to be the simplest solution. Do you see any problem with it?

   What does the second argument in the window.open function do? (In your example it is "Link", in mine it is ''.)

   Thanks, Ted
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 35

Accepted Solution

by:
YZlat earned 250 total points
ID: 9690005
it's an optional argument. it specifies the name of the window you are about to open. You might need it if you'll want to refer to that window
0
 

Expert Comment

by:mad_avan2003
ID: 10352832
in the same popup window, how to remove the title bar, i mean i have to remove the minimize, maximize and close button. i just want the frame.
thanks in advance.
0
 

Expert Comment

by:jericho_law
ID: 11673265
i think this might be useful to those who wants to generate a new window after u have done some tasks.
This code is auto generate as its a response.write
What it does is to actually pop-out a new window.
The dimensions and location of the new window can be specify to your requirements.

Response.Write("<script language = ""Javascript"">var win=window.open('limitAlert.aspx',null,'width=510,height=255,top=250,left=250','true');</script>")

But after you have opened a new window, i can't open another new window.
I wanted the have another new window after i redirect to 'limitAlert.aspx'.
But the new page seems to just override the current window page ('limitAlert.aspx').

How can i open a new window and then open another new window that is separate from 1 another?
0
 

Expert Comment

by:csuttman
ID: 11835627
I had a consultant do some work and he used RegisterStartupScript throughout the site to pass javascript back to the page in order to open a new window controlling size, menubar, etc. of it. PROBLEM is... it puts javascript on the page that automatically opens this new window when the page loads... which pop-up blockers don't like. Pop-up blockers don't block user initiated onClick events, but javascript that isn't user controlled is blocked

We tried getting around it by openning dialogue windows instead of window.open whic worked, except no menubar is shown.

I'm almost to the point to not open any windows from the site... which would really suck. I need to keep a main window open and open reports in additional windows. Sometimes multiple reports to compare side-by-side. I really don't want to re-write the entire site to get windows to open either

Is there a way to open a new window after doing some processing server side that doesn't get blocked by pop-up blockers???

HELP!!!  PLEASE!!! IT'S DRIVIN' ME NUTS!!!
0
 
LVL 4

Expert Comment

by:Sicos
ID: 11840066
>> How can i open a new window and then open another new window that is separate from 1 another?
>>Response.Write("<script language = ""Javascript"">var win=window.open('limitAlert.aspx',null,'width=510,height=255,top=250,left=250','true');</script>")

Just replace the "null" with a unique nam, not longer than 8 chars and no spaces and special chars.

Greetings
Sicos
0
 

Expert Comment

by:GARRADPE
ID: 11971304
Hi

with regard to the soluiton javascript:var w=window.open('TestPage.aspx','', 'width=625,height=760,scrollbars=yes,resizeable=yes'); how do you stop this destroying the original aspc page. When I use this code and similar javascripts to contorl a hyper link url the original page seems to loose the original object and the javascript ends up in the address bar of the original window.

Any ideas would be appreciated.
0
 

Expert Comment

by:strout
ID: 12440057
Try add void('');

like this
<asp:HyperLink id="lnk" runat="server" NavigateUrl="javascript:window.open('http://yahoo.com',null, 'height=200, width=400, status=yes, toolbar=no, menubar=no, location=no'); void('');"> click here</asp:HyperLink>

strout
0
 

Expert Comment

by:knkmurali
ID: 12633068
First you take an ordinary Html page example: Page1.html
in that add the script
<script language=javascript>
    setTimeout( "window.open('Page2.aspx','link','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1')",10);
    this.close
</script>

Then From page2.aspx onwards no Addressbar, History Back or Forward Buttons.,So the User Can't Go to History..
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question