ASP.NET - Link button in asp.net should open i n new window.

Asked By srinivas kandukuri on 21-Feb-11 06:01 AM
Hi ,
I have  a link button..
What i want is when i click on it it should be opened in a new ,separate window..


Thanks in asvance,
thank you..
Jatin Prajapati replied to srinivas kandukuri on 21-Feb-11 06:11 AM
Hi,
Please refer below code example. This will give you an idea about this.

<%@ Page Language="C#" Trace="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
       
    }
  }
 
  protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      LinkButton lb = e.Row.FindControl("lbDetail") as LinkButton;
      if (lb != null)
      {
        lb.OnClientClick = string.Format("window.open('Details.aspx?ID={0}'); return false;", GridView1.DataKeys[e.Row.RowIndex].Value);
      }
    }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <script language="javascript" type="text/javascript">
    window.print();
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
     
  </div>
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1" DataKeyNames="ProductID" OnRowCreated="GridView1_RowCreated">
    <Columns>
      <asp:TemplateField HeaderText="Product Name">
        <ItemTemplate>
          <%#Eval("ProductName") %>'
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit"
        SortExpression="QuantityPerUnit" />
      <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice"
        SortExpression="UnitPrice" />
      <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock"
        SortExpression="UnitsInStock" />
      <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder"
        SortExpression="UnitsOnOrder" />
      <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel"      
        SortExpression="ReorderLevel" />
      <asp:TemplateField HeaderText="Product Name">
        <ItemTemplate>
          <asp:LinkButton ID="lbDetail" runat="server" Text="Detail"></asp:LinkButton>
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
  </asp:GridView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"    
    SelectCommand="SELECT [ProductID], [ProductName], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [ReorderLevel] FROM [Products]" >     
  </asp:SqlDataSource>
  </form>
</body>
</html>

Santhosh N replied to srinivas kandukuri on 21-Feb-11 06:18 AM
You could use something liek this

strURL = Request.ApplicationPath + "/page2.aspx"; 
string strWinProperty = "toolbar=no,menubar=no,location=no"; 
 
LinkButton lnkbtnHelp = (LinkButton)Login.FindControl("lnkbtnHelp"); 
 
lnkbtnHelp
.Attributes.Add("onClick", "javascript:window.open('" + strURL + "','" + strWinProperty + "');return false;");
Subhashini Janakiraman replied to srinivas kandukuri on 21-Feb-11 07:23 AM
You can use the Modal Popup extender from the AjaxControlToolkit and extend it to the Panel to display the popup window the way we want on click of a  link button.Go through the tutorials to know about the same.
help
initiate print option on page load ASP.NET 10-Aug-13 06:24 PM i have developed a print.css will take effect. HI you have to call window.print(); javascript on onclick event if you are using asp:button, asp:imagebutton, asp:linkbutton then OnClientClick = "window.print(); return false;" On Click of button on on page load write this code 1. Response.Write("<Script> window.print()< / Script> ") 2. For page break wirte below code on
Print the page in ASP.net 10-Aug-13 06:43 PM I need a code for this give me a code you have to call window.print(); javascript on onclick event if you are using asp:button, asp:imagebutton, asp:linkbutton then OnClientClick = "window.print(); return false;" On Click of button on on page load write this code 1. Response.Write("<Script> window.print()< / Script> ") 2. For page break wirte below code on
problem with reloading my webpage automatically ASP.NET 10-Aug-13 06:30 PM hi. . i have grid title > < / title > 35. < script language = "javascript" type = "text / javascript" > 36. window.print(); 37. < / script > 38. < / head > 39. < body > 40. < form id = "form1 56. < asp:TemplateField HeaderText = "Product Name" > 57. < ItemTemplate > 58. < asp:LinkButton ID = "lbDetail" runat = "server" Text = "Detail" > < / asp:LinkButton > 59. < / ItemTemplate > 60. < / asp:TemplateField > 61. < / Columns > 62. < / asp:GridView
What is application Control in asp.net ASP.NET 10-Aug-13 06:21 PM What is application Control in asp.net? ASP.NET Web server controls are objects on ASP.NET Web pages
What is Http Handler in ASP.NET ASP.NET 10-Aug-13 06:22 PM Can any one explain about What is Http Handler in ASP.NET An ASP.NET HTTP handler is the process (frequently referred to as the
which book is good for reference for asp.net ASP.NET 10-Aug-13 06:25 PM i want refer asp.net E book . . which book is better for refer. . pls tell me Hi, Professional ASP.NET 3.5 Book : http: / / weblogs.asp.net / scottgu / archive / 2008
Tracing in ASP.NET? ASP.NET 10-Aug-13 06:24 PM hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution
asp.net ASP.NET 10-Aug-13 06:17 PM hi, how gridiview is used in uploading multiple images in asp.net check this link. . . http: / / weblogs.asp.net / imranbaloch / archive / 2010 / 04 / 03 / image-preview-in-asp-net
Question about MVC2 using C# and ASP.NET ASP.NET 10-Aug-13 06:24 PM can anybody give me single web page) from controller? Thank you in advance. . HI ASP.NET MVC 2 We shipped ASP.NET MVC 1.0 last March. Since then, almost 1 million