window.open -- how to keep original page

G

Guest

Hello,

I have a link on an aspx page. The URL is set in the Page Load event:

lnkEventHistory.NavigateUrl =
"javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("SubjectID") & "&EventCode=" &
Request.Item("EventCode") & "')"

When I click the link, the new window opens as expected. The problem is
that on the original page containing the link, everything disappears and is
replaced with just this:

[object]

Can anyone tell me why this is happening and how I can keep the original
page intact while popping up the new window?

Thanks very much.
 
S

Steve C. Orr [MVP, MCSD]

Output a standard HTML anchor tag with the Target attribute specified.
<a href="EventHistory.aspx" target='_blank'>click me</a>
 
G

Guest

Thank you for your reply. I'm still wrestling with this. Let me give some
more background.

I tried two things based on your suggestion:

1) I created a label on the form. On the Page Load event, I set the text of
the label to this:

lblEventHistoryLink.Text = "<a href='EventHistory.aspx?TeenID=" &
Request.Item("SubjectID") & "&EventCode=" & Request.Item("EventCode") & "'
target='_blank'>View Event History</a>"

This sort of worked, except that I need to use Javascript's window.open
method so that I can set the new window's size, menubars, etc.

2) Second thing I tried -- On my original hyperlink, which is an ASP Web
control, I set the Target to "_blank" in the Properties window. When I run
it and click the link, I get two new windows:

- The first is a blank page that has the text "[object]" in it. The
address bar says:
javascript:window.open('EventHistory.aspx?TeenID=123&EventCode=10')

- The second window is the page that I actually want.

Is there any way to get rid of this intermediate "[object]" window?

Any other ideas I can try?

Thanks.

Steve C. Orr said:
Output a standard HTML anchor tag with the Target attribute specified.
<a href="EventHistory.aspx" target='_blank'>click me</a>





Chris said:
Hello,

I have a link on an aspx page. The URL is set in the Page Load event:

lnkEventHistory.NavigateUrl =
"javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("SubjectID") & "&EventCode=" &
Request.Item("EventCode") & "')"

When I click the link, the new window opens as expected. The problem is
that on the original page containing the link, everything disappears and
is
replaced with just this:

[object]

Can anyone tell me why this is happening and how I can keep the original
page intact while popping up the new window?

Thanks very much.
 
G

Guest

I just tried a third idea. I added the window.open to the href in the
standard HTML anchor, like this:

Dim strhref As String
strhref = "javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("TeenID") & "&EventCode=" &
Request.Item("EventCode") & "')"
lblEventHistoryLink.Text = "<a href=""" & strhref & """
target=""_blank"">View Event History</a>"

I'm getting the same behavior as with the ASP Web control hyperlink -- an
intermediate window containing only the text "[object]" opens in addition to
the final desired window.

So I don't think the problem is with the standard HTML anchor versus the ASP
Web control hyperlink. There must be some subtlety of Javascript that I am
missing.

Can anyone help me?
 
S

Steve C. Orr [MVP, MCSD]

You need to execute two lines of JavaScript:

Window.Open(...);
Document.location='page2.aspx';




Chris said:
I just tried a third idea. I added the window.open to the href in the
standard HTML anchor, like this:

Dim strhref As String
strhref = "javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("TeenID") & "&EventCode=" &
Request.Item("EventCode") & "')"
lblEventHistoryLink.Text = "<a href=""" & strhref & """
target=""_blank"">View Event History</a>"

I'm getting the same behavior as with the ASP Web control hyperlink -- an
intermediate window containing only the text "[object]" opens in addition
to
the final desired window.

So I don't think the problem is with the standard HTML anchor versus the
ASP
Web control hyperlink. There must be some subtlety of Javascript that I
am
missing.

Can anyone help me?


Chris said:
Hello,

I have a link on an aspx page. The URL is set in the Page Load event:

lnkEventHistory.NavigateUrl =
"javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("SubjectID") & "&EventCode=" &
Request.Item("EventCode") & "')"

When I click the link, the new window opens as expected. The problem is
that on the original page containing the link, everything disappears and
is
replaced with just this:

[object]

Can anyone tell me why this is happening and how I can keep the original
page intact while popping up the new window?

Thanks very much.
 
M

Matt Berther

Hello Chris,
lnkEventHistory.NavigateUrl =
"javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("SubjectID") & "&EventCode=" &
Request.Item("EventCode") & "'); return false"

Note the addition of the 'return false'. This instructs the browser to stop
processing.

--
Matt Berther
http://www.mattberther.com
Hello,

I have a link on an aspx page. The URL is set in the Page Load event:

lnkEventHistory.NavigateUrl =
"javascript:window.open('EventHistory.aspx?TeenID=" & _
Request.Item("SubjectID") & "&EventCode=" &
Request.Item("EventCode") & "')"
When I click the link, the new window opens as expected. The problem
is that on the original page containing the link, everything
disappears and is replaced with just this:

[object]

Can anyone tell me why this is happening and how I can keep the
original page intact while popping up the new window?

Thanks very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top