Solved

Open New Window from ASP.Net control and specify dimensions

Posted on 2003-11-04
11
200,106 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MVC and Angular 2 130
JQuery tracking event. 3 89
Problem to ToolkitScriptManager 2 86
Adjust the position 3 75
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

739 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