LinkButton or HyperLink?

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

+4
source share
7 answers

I would say that HyperLink refers to a specific URL to store the necessary session data, then use it Response.Redirectto redirect to the next page after saving the information.

The HyperLink URL will point to your server so that you can save the information, and then you will use the redirection to tell the user the correct endpoint after storing the necessary data.

Example

  • URL-address HyperLink indicates ~/yourpage.aspx?state=NY,target="_blank"
  • The server responds to the URL and validates the request.
  • If the query string exists, save the data ( if (Request.QueryString["state"] != null) Session["state"] = Request.QueryString["state"])
  • Redirect user to appropriate url ( Response.Redirect("http://www.ny.gov"))

If the data is confidential, then you would like to use the methods LinkButtonspecified in other answers. Opening a new tab is difficult, so you will probably have to write some Javascript, as indicated by @andleer, since I do not believe that there is an easy way to open a new window from the server side otherwise.

+2

A LinkButton postback, , , , . response.redirect(url) , .

, , , Jquery ?

LinkButton

Click Api with Jquery Jquery post.

+3

LinkButton, PostBack. , JavaScript.

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

    Page.ClientScript.RegisterStartupScript(Page.GetType(),
            "newWindow",
            "window.open('http://myurl','_blank');",
            true);
}
+3

LinkButton.

, LinkButton , , HyperLink - , HyperLink, .

+1

LinkButton . HyperLink, , Button. LinkButton - .

+1

, , LinkButton , .

LinkButton, ( ) , . ( )

0

, . , . javascript URL- , , -.

-1

All Articles