Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkButton or HyperLink?

Tags:

html

c#

asp.net

I have a situation where I'm not sure if I should use a HyperLink or LinkButton. When a user clicks on a list of links I want to trigger a click event where I save some information to session (should use LinkButton) but I also want these links to open up new tabs (should use HyperLink).

like image 440
Teeknow Avatar asked Jan 12 '23 02:01

Teeknow


2 Answers

A LinkButton will postback, it's essentially a button that renders like a link. You could set a response.redirect(url) in the event handler to set a new tab.

Can you add more information, of what you want to do in the handler, maybe this could be achieved with Jquery calling a server-side method?

Difference between Hyperlink and LinkButton

Click Api with Jquery and Jquery post.

like image 124
Christian Phillips Avatar answered Jan 22 '23 01:01

Christian Phillips


You will need to use a LinkButton which causes a PostBack. To open additional tabs, emit JavaScript.

protected void MyLinkButton_Click(object sender, EventArgs e)
{
    Session["MyData"] = 123;

    Page.ClientScript.RegisterStartupScript(Page.GetType(),
            "newWindow",
            "window.open('http://myurl','_blank');",
            true);
}
like image 32
andleer Avatar answered Jan 22 '23 03:01

andleer