C# LinkButton.PostBackUrl - New window without JS

25,741

As i know linkbuttons were originally designed to do a postback to the same page

If i were you i would use a hyperlink control instead

Share:
25,741
Juri Bogdanov
Author by

Juri Bogdanov

Updated on August 25, 2020

Comments

  • Juri Bogdanov
    Juri Bogdanov almost 4 years

    Is it possible to use asp:LinkButton without JavaScript to open new windows? Currently i have workable next code, but with JS.

    <asp:LinkButton ID="lnkPcName" runat="server" OnClientClick="window.document.forms[0].target='_blank';" PostBackUrl='<%# Eval("ComputerId", "ComputerInfo.aspx?ComputerId={0}") %>'><%# Eval("pcName") %></asp:LinkButton>
    
  • Juri Bogdanov
    Juri Bogdanov almost 15 years
    Yeah! Thanks guru! :P I replaced it with <asp:HyperLink ID="lnkPcName" runat="server" Target="_blank" NavigateUrl='<%# Eval("ComputerId", "ComputerInfo.aspx?ComputerId={0}") %>'><%# Eval("pcName") %></asp:HyperLink> And no more JavaScript error!!!!
  • SearchForKnowledge
    SearchForKnowledge almost 10 years
    I want to emulate the OnClick in my LinkButton through HyperLink. How can I achieve that? Thanks.