JavaScript How to open link in new tab with Link Button open link with app,open link with specific browser,open

I have a gridview with the HeaderTemplate and it contains a LinkButton. When I click the button I want to open a link in new tab

<asp:TemplateField>
     <HeaderTemplate>
      <asp:LinkButton ID="lnkbtn" runat="server" OnClientClick="SetTarget();" OnClick="lbtn_Click">Topics</asp:LinkButton>
     </HeaderTemplate>
<ItemTemplate>
........
</ItemTemplate>

My JavaScript

<script type = "text/javascript">
        function SetTarget() {
            document.forms[0].target = "_blank";
        }
</script>

And the OnClick event is

protected void lbtn_Click(object sender, EventArgs e)
{
  Response.Redirect("http://www.google.com/");
}

This is opening the link in new tab. But I have other LinkButton outside the gridview for other processes such as Saving the data, etc.,.

<asp:LinkButton ID="LinkButton1" runat="server">Save</asp:LinkButton>

But when I even click this button it is opening new tabs.How can I prevent them from opening in new tabs

Answer:1

Is there a reason why you want to redirect on the server-side? You could just do

function redirectToGoogle(){
   window.open('google.com');
   return false;
}

and

<asp:LinkButton ID="lnkbtn" runat="server" OnClientClick="return redirectToGoogle();" ....

When you're setting ASP form's target, every link or form post will target new window. So you're going to have to undo form's target on every other LinkButton click or form submission.

Answer:2

This is a generic JS question. In React-leaflet, I want to handle events via callbacks. The called function gets the caller (event) context which can be used to do stuff like this.getZoom(). ...

This is a generic JS question. In React-leaflet, I want to handle events via callbacks. The called function gets the caller (event) context which can be used to do stuff like this.getZoom(). ...

I tried different methods, mostly people suggest to use img instead of a background-image to get the perfect result, but I was wondering is it possible to fix this with just some tricks and have a ...

I tried different methods, mostly people suggest to use img instead of a background-image to get the perfect result, but I was wondering is it possible to fix this with just some tricks and have a ...

  1. how to make fully responsive website
  2. how to make fully responsive website using bootstrap

Anyone know what the null is in this line: React.DOM.p(null, message); I'm aware it's a convenience wrapper around createElement, i.e. ReactElement createElement( string/ReactClass type, [...

Anyone know what the null is in this line: React.DOM.p(null, message); I'm aware it's a convenience wrapper around createElement, i.e. ReactElement createElement( string/ReactClass type, [...

I have a function that does some async work and returns a Promise, and I want to execute this function indefinitely until the promise is rejected. Something like the following : doSomethingAsync(). ...

I have a function that does some async work and returns a Promise, and I want to execute this function indefinitely until the promise is rejected. Something like the following : doSomethingAsync(). ...