John
John

Reputation: 3945

change from hyperlink to link btn

Had to change from asp:hyperlink to asp:linkButton, can no longer use navigateUrl in link button...any suggestions?

<asp:LinkButton ID="InvoiceLink" runat="server" NavigateUrl="~/Invoices/List.aspx">
           <asp:Label id="labelBindfromHomeToInvoice" runat="server" Text="<%# Bind('Site_Name') %>"/>
        </asp:LinkButton>

Upvotes: 0

Views: 774

Answers (3)

Agustin Meriles
Agustin Meriles

Reputation: 4854

LinkButton doesn't work that way. LinkButton is more like a Button with a Hyperlink appeareance. So you can handle the OnClick Event.

<asp:LinkButton ID="InvoiceLink" runat="server" OnClick="InvoiceLink_Click">
    <asp:Label id="labelBindfromHomeToInvoice" runat="server" Text="<%# Bind('Site_Name') %>"/>
</asp:LinkButton>

In the CodeBehind

protected void InvoiceLink_Click(object sender, EventArgs e)
{
    Response.Redirect("~/Invoices/List.aspx");
}

EDITED

I will improve this answer. The main difference between HyperLink and LinkButton is that HyperLink will not PostBack, it just simply request the NavigateURL to the server. The LinkButton is just a normal Button. This means that it will PostBack the server, with all the advantages and disadvantages to doing this (sending ViewState for example, update the controls, etc)

If you need just to redirect to another page, probably the best choice it will be HyperLink

Upvotes: 1

nunespascal
nunespascal

Reputation: 17724

On a link button you use the PostBackUrl

<asp:LinkButton ID="InvoiceLink" runat="server"
     PostBackUrl="~/Invoices/List.aspx">

Upvotes: 1

walther
walther

Reputation: 13600

LinkButton uses PostBackUrl, because you "post" the data to another url.

Upvotes: 1

Related Questions