|
 |
aspx_beginners thread: Openning a second page
Message #1 by "Randy McBride" <mcbride@b...> on Wed, 5 Jun 2002 14:53:05 -0700
|
|
I need to open a second page while the first one remains open. The second
page is only going to be used to display Help for the first page. I have
done this on windows forms, but it seems that security prevents me from
doing the same from a web page.
Thanks,
Randy
Message #2 by "Dan McKinnon" <mddonna@q...> on Thu, 6 Jun 2002 09:58:52
|
|
> I need to open a second page while the first one remains open. The
second page is only going to be used to display Help for the first page.
I have done this on windows forms, but it seems that security prevents me
from doing the same from a web page.
Randy -
This can be easy, or it can get involved, depending on what you want to
do.
If you just want to open a new window, it can be as easy as putting a
target attribute in a hyperlink.
<a href="new.aspx" target="newWindow">text or pic</a>
Assuming that the original window (that contains the hyperlink, and is
called the 'opener' in JavaScript) is not named newWindow, this will put
new.aspx in a new browser window, and any code in the new.aspx page will
execute on the server before it opens.
Or you can use client-side JavaScript to open the window. This deals with
the window.open() method, which takes basically three parameters, though
the third one is actually all the attributes of the new window like width
and size, whether it has a scrollbar, and so on.
<script language="JavaScript">
var openWindow = window.open("new.aspx","newWindow",width=150,height=150);
</script>
The first parameter is the page you want to load into the new window, the
second parameter is the name of the new window, and the third (and fourth
and fifth, etc. if present) is as I described above. There are about a
dozen things you can control in the new window (listed after the second
parameter), which are listed in "Beginning JavaScript" by Paul Wilton on
page 264 (a book I highly recommend).
If you want to pass variables from the opener window to the opened
window, that is, form information, then you would set the target
attribute of the form in the opener window to the name of the new window.
(I've never done this, but I'm reading about it in the JavaScript book.)
I'm sure MS has figured out (probably easier) ways to do all this with
server controls.
HTH,
Dan
Message #3 by "Randy McBride" <mcbride@b...> on Thu, 6 Jun 2002 08:13:16 -0700
|
|
Thanks for the help. I have not used JavaScript enough to be very
comfortable with it. Here was what I finally stumbled across that worked:
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:HyperLink id="hyperlink1" ImageUrl="images/pict.jpg"
NavigationUrl="mypage" Text="MyText" Target="_new" runat="server" />
other controls would be here.......
</form>
</body>
The thing that seems to be different then a standard hyperlink is that
Target="_new".
This appears to be doing what the window.open() function is doing in
JavaScript. From what I see it appears that I probaly should work on my
JavaScript more to save myself some of these types of headaches though.
Thanks again for responses.
Message #4 by "Dan McKinnon" <mddonna@q...> on Fri, 7 Jun 2002 01:09:25
|
|
Hi Randy -
Thanks for posting this. It looks like it's setting the target attribute
in the form, as suggested in my JS book. If I get ambitious I will run
this in VS and see what the html output looks like.
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:HyperLink id="hyperlink1" ImageUrl="images/pict.jpg"
NavigationUrl="mypage" Text="MyText" Target="_new" runat="server" />
other controls would be here.......
</form>
</body>
>>The thing that seems to be different then a standard hyperlink is that
Target="_new".<<
In standard html you can set a target attribute to _new (opens a new
window), _self (loads new page into the same window, _blank (does the
same thing as _new), _parent (loads to parent window), or _top (loads new
page to top window in a frame). MS has adapted their server controls and
html controls that runat=server to these html protocols.
Dan
|
|
 |