?
Solved

Open New Window from ASP.Net control and specify dimensions

Posted on 2003-11-04
11
Medium Priority
?
200,176 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Accepted Solution

by:
YZlat earned 750 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

862 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