Solved

Open New Window from ASP.Net control and specify dimensions

Posted on 2003-11-04
11
200,059 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
Comment Utility
you can use <asp:hyperlink target=_blank>
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
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
Comment Utility
  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
 
LVL 35

Accepted Solution

by:
YZlat earned 250 total points
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:jericho_law
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now