Link to home
Start Free TrialLog in
Avatar of tk3
tk3

asked on

Open New Window from ASP.Net control and specify dimensions

  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
Avatar of YZlat
YZlat
Flag of United States of America image

you can use <asp:hyperlink target=_blank>
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')")
Avatar of tk3
tk3

ASKER

  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
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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?
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!!!
>> 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
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.
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
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..