Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Target="_blank" in a LinkButton

is it possible to have a target="_blank" in LinkButton...mine doesnt seem to be working

<asp:LinkButton runat="server" ID="g31" Text="PDF" 
    CommandArgument='<%# DataBinder.Eval(Container.DataItem,"productID") %>'
    CommandName='<%# DataBinder.Eval(Container.DataItem,"documentID") %>'
    OnCommand="linkbutton_showpdf" target="_blank">
</asp:LinkButton>

Or would I have to use a different button format?

like image 537
user979331 Avatar asked Feb 13 '12 04:02

user979331


3 Answers

You can use like this with Link Button

Replace target="_blank" to OnClientClick="window.document.forms[0].target='_blank';".

like image 99
Devsainii Avatar answered Sep 23 '22 06:09

Devsainii


None of the current answers are correct, even the <a> tag is not the correct answer in asp.net.

Use the HyperLink Button. There is even a property for the target attribute.

<asp:HyperLink runat="server" 
    NavigateUrl='http://rrs.com/aspx/Equipment/EquipmentType.aspx'
    Target="_blank">
        Create/Edit Part Types
</asp:HyperLink>
like image 27
M H Avatar answered Sep 20 '22 06:09

M H


You can use the Hyperlink control, which does have a target='_blank' property. However if you must use a LinkButton control, then you can add a OnClientClick attribute which then calls a JavaScript function to open a popup window

window.open();
like image 41
skub Avatar answered Sep 22 '22 06:09

skub