Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a link button in grid view and on click of the link button i have assigned a url and it is redirecting in the same tab, Can we redirect to a different tab or different window ?

What I have tried:

<asp:LinkButton ID="LinkButton1" runat="server"  OnCommand="LinkButton_Click"  Text="Link" CommandArgument='<%# Eval("T_Link") %>'></asp:LinkButton>


protected void LinkButton_Click(Object sender, CommandEventArgs e)
  {
      strURL = "";
      LinkButton lb = (LinkButton)sender;
      GridViewRow row1 = (GridViewRow)lb.NamingContainer;
      strURL = e.CommandArgument.ToString();
      Response.Redirect(strURL);
  }
Posted
Updated 18-Oct-17 0:39am
Comments

LinkButton unfortunately hides the standard 'target'[^] attribute...
You may use simple HTML code or the HyperLink[^] control...
 
Share this answer
 
try

protected void LinkButton_Click(Object sender, CommandEventArgs e)
       {
            strURL = "";
           LinkButton lb = (LinkButton)sender;
           GridViewRow row1 = (GridViewRow)lb.NamingContainer;
           strURL = e.CommandArgument.ToString();
           Response.Write("<script>");
           Response.Write("window.open('"+strURL+"','_blank')");
           Response.Write("</script>");
       }


Alternate and effective solution
replace the linkbutton with an anchor tag
<a href='<%# Eval("T_Link") %>' target="_blank">Link</a>
 
Share this answer
 
v3
Comments
Kornfeld Eliyahu Peter 18-Oct-17 6:43am    
While it will work I think that doing postback for a simple navigation task is a bit too much...
Karthik_Mahalingam 18-Oct-17 6:58am    
yes it is little expensive but have given solution based on his approach, however i have updated the simplest solution too :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900