<a> vs <asp:linkbutton> for new window

G

George Durzi

I currently have an href inside of an asp:repeater

<a href='<%# String.Concat("PDFReader.aspx?id=",
DataBinder.Eval(Container.DataItem, "ProductUniqueId")) %>'
target="_blank">View</a>

Clicking View will open a new browser and load PDFReader.aspx


My client would like me to hide the address bar and toolbar on this new
window.

Here's what I was thinking:

1. Change the Href to an <asp:linkbutton>, something like this:

<asp:linkbutton id="lnkView" runat="server" text="View"/>

2. On the ItemCreated event of the Repeater

Add an onclick attribute to the linkbutton.

something like (pseudo code)

(linkbutton) repeater.findcontrol("lnkView").Attributes.Add("onclick",
"window.open("Product.aspx?id=", null,
"toolbar=no,menubar=no,location=no")");

my issue is, I need to append a querystring value to id= so the url I'm
going to is actually "Product.aspx?id=" + ProductUniqueId

How can I do this?
 
K

Karl

Why not just do something like:
<a href="<%#"javascript:window.open('PDFReader.aspx?id=" +
DataBinder.Eval(Container.DataItem, "ProductUniqueId") + "',null,
'toolbar=no,menubar=no,location=no');" %>">edit</a>

Karl
 
T

Thomas Dodds

(linkbutton)
repeater.findcontrol("lnkView").Attributes.Add("onclick","window.open('Produ
ct.aspx?id=" + ProductUniqueId + "',
null,'toolbar=no,menubar=no,location=no')");
 
G

George Durzi

Thanks Karl, I feel stupid not thinking of that. Don't know why I thought I
had to add an attribute to the LinkButton for its onclick.
 
G

George Durzi

Karl,
A weird thing happens now when you click the href. It open the new window
properly. However the starting window now just says "[object]" in the
window.

If I put a target="_blank" in the href, I end up with three windows.

The original window
A window with "[object]" in it
and the window opened by the window.open command
 
K

Karl

Thomas' idea will work too..and is normally what I'd advocate. If you have
having problems with my code, make sure you got your single and double
quotes perfectly...it took me more than a couple tries to get all my i's
dotted and my t's crossed :)

Karl

George Durzi said:
Karl,
A weird thing happens now when you click the href. It open the new window
properly. However the starting window now just says "[object]" in the
window.

If I put a target="_blank" in the href, I end up with three windows.

The original window
A window with "[object]" in it
and the window opened by the window.open command

Karl said:
Why not just do something like:
<a href="<%#"javascript:window.open('PDFReader.aspx?id=" +
DataBinder.Eval(Container.DataItem, "ProductUniqueId") + "',null,
'toolbar=no,menubar=no,location=no');" %>">edit</a>

Karl
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top