title: Avoid page refresh when clicking on LinkButton in grid
body: <p>I have a <code>GridView</code> control, and inside of this control I have defined a link button using <code>GridView.ItemTemplate</code>.</p>
  
  <p>I am using this to open a new window on click. When I click on the link button, however, the page refreshes before opening the new window.</p>
  
  <p>How can I stop the page from refreshing after the link button is clicked?</p>
  
  <p>Pop up is not displaying when i add Update panel to first grid</p>
  
  <p>if i remove Update panel from first grid, grid is refreshing and popup is displaying</p>
  
  <p>I need to open a popup without refreshing my grid</p>
  
  <p>PLEASE FIND ME THE SOLUTION FOR THIS AS I WAS WORKING ON THIS FROM PAST 2 DAYS</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;%@ Page Language="c#" AutoEventWireup="false" CodeFile="ViewData1.aspx.cs" Inherits="ablesas.ViewDataUI1" EnableEventValidation="false"%&gt;
  
  
              &lt;asp:UpdatePanel ID="UpdatePanel4" runat="server"&gt;
                          &lt;ContentTemplate&gt;
  
                                           &lt;asp:GridView ID="DataGrid1"  style="visibility:visible" runat="server" AlternatingRowStyle-BackColor="#E9EDF5"  Font-Names="Arial"
                                                  ForeColor="#09538A" Font-Size="12px" BackColor="#ffffff" BorderColor="DarkGray" Font-Bold="true" 
                                                  HeaderStyle-BackColor="#298DC7" EnableViewState="false"  CellSpacing="20" 
                                                  CellPadding="10"  HeaderStyle-Font-Bold="true"  AutoGenerateColumns="False" OnRowCommand="DataGrid1__RowCommand" OnRowDataBound="DataGrid1__RowDataBound" &gt;
                                                  &lt;HeaderStyle Font-Names="Arial;" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="White" Font-Bold="True" Height="20"  BackColor="#298DC7" &gt;&lt;/HeaderStyle&gt;
          &lt;asp:templatefield headertext="NDC" ItemStyle-CssClass="col" ItemStyle-HorizontalAlign="Justify" HeaderStyle-Width="10%" ItemStyle-Width="10%"&gt;                                     &lt;Columns&gt;               
                      &lt;itemtemplate&gt;
                      &lt;asp:linkbutton id="productcode"   ForeColor="#09538A" runat="server"  text='&lt;%#Eval("product code")%&gt;'&gt;&lt;/asp:linkbutton&gt;                               
  
                                                       &lt;/itemtemplate&gt;
                                          &lt;/asp:templatefield&gt;
                     &lt;/asp:GridView&gt;
                                  &lt;/ContentTemplate&gt;
                  &lt;/asp:UpdatePanel&gt;
  
  
                                          &lt;AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1"   BackgroundCssClass="modalBackground" CancelControlID="cancel" TargetControlID="Button3" runat="server" PopupControlID="pnlpopup"&gt; &lt;/AjaxToolkit:ModalPopupExtender&gt;
      &lt;asp:Panel id="Panel1"  runat="server" Height="30px" Width="600px"&gt;
      &lt;/asp:Panel&gt;        
                     &lt;asp:Button ID="Button3" runat="server" style="visibility:hidden" Text="Button" /&gt;
                              &lt;asp:Panel ID="pnlpopup" CssClass="PanelPopup"  runat="server"&gt;
                                          &lt;div  style="width:inherit;text-align:center;"&gt;Products of &lt;%=ndc %&gt; Product Family&lt;/div&gt;
                                          &lt;asp:GridView ID="GridView1"  runat="server" AlternatingRowStyle-BackColor="#f1f4f8"  Width="980px" Font-Names="Arial"
                                              Font-Bold="True" ForeColor="#09538A" Font-Size="13px" BackColor="#ffffff" BorderColor="DarkGray"
                                              HeaderStyle-BackColor="#99cccc" EnableViewState="false"  CellSpacing="0" style="padding:10px;"
                                              CellPadding="3" ShowFooter="false" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="productInfo_RowDataBound" &gt;
                                              &lt;HeaderStyle Height="10%" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="true"  BackColor="#298DC7"&gt;&lt;/HeaderStyle&gt;
                                              &lt;rowstyle Height="20px" /&gt;
                          &lt;alternatingrowstyle  Height="20px"/&gt;
                                              &lt;Columns&gt;
                  &lt;asp:boundfield  datafield="product code" sortexpression="customers " ItemStyle-CssClass="col" headertext="NDC"/&gt;
  
               &lt;div id="div&lt;%#  Convert.ToString(Eval("customer"))+ Convert.ToString(Eval("ManufacturingPartner"))+ Convert.ToString(Eval("product code"))+ Convert.ToString(Eval("Sales Person")) %&gt;" style="display: none; position: relative; left: 15px; overflow: auto"&gt;
                                          &lt;asp:GridView ID="gvOrderInfo" runat="server" ForeColor="#09538A"  AutoGenerateColumns="false" BorderStyle="Double"  BorderColor="#df5015"  Width="500px" OnRowDataBound="gvOrderInfo_RowDatabound"&gt;
                                          &lt;HeaderStyle CssClass="MyHeaderStyle"  Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="True"  BackColor="#298DC7"&gt;&lt;/HeaderStyle&gt;
                                          &lt;RowStyle BackColor="#E1E1E1" /&gt;
                                          &lt;AlternatingRowStyle BackColor="White" /&gt;
                                          &lt;HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" /&gt;
                                          &lt;Columns&gt;
                &lt;asp:BoundField DataField="Order Number" HeaderText="Order Number" ItemStyle-Width="75px" ItemStyle-CssClass="col" HeaderStyle-HorizontalAlign="Left" /&gt;
                    &lt;/Columns&gt;   
                &lt;/Columns&gt;                            
                                          &lt;/asp:GridView&gt;
                                      &lt;/div&gt;                         
                                              &lt;/asp:GridView&gt;
               &lt;/asp:Panel&gt;
  </code></pre>
  
  <p><strong>Codebehind</strong></p>
  
  <pre><code>  protected void DataGrid1__RowDataBound(Object sender, GridViewRowEventArgs e)
      {    
           this.UpdatePanel4.Update();
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
                LinkButton lnk = e.Row.FindControl("productcode") as LinkButton;
                lnk.Click += new EventHandler(link_Click);
  
                //ScriptManager.GetCurrent(this).RegisterPostBackControl(lnk); 
  
                // string a = String.Format("0:N}",Convert.ToDecimal(e.Row.Cells[3].Text));
                if (e.Row.Cells[0].Text != "Total")
                {
                      //M1-Fmodification starts from here
                      if (ListBox2.Items.Count &gt; 0)
                      //if (DataGrid1.Columns[0].Visible == true)
                      {
                      }              
                }
           }
      }
  </code></pre>
  
  <p><strong>Codebehind</strong></p>
  
  <pre><code> public void productcode_Click(object sender, EventArgs e)
          {
              pnlpopup.Visible = true;
              //UpdatePanel3.Update();
              //this.UpdatePanel3.Update();
              GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
              LinkButton lbtn = (LinkButton)clickedRow.FindControl("productcode");
              string customer = clickedRow.Cells[0].Text.ToString();
              string manufacturer = clickedRow.Cells[5].Text.ToString();
              string salesperson = clickedRow.Cells[6].Text.ToString();
              System.Data.DataTable newProductTable = null;
              ArrayList productDrilldownList = new ArrayList();
              productDrilldownList.Add(customer);
              productDrilldownList.Add(manufacturer);
              productDrilldownList.Add(lbtn.Text);
              productDrilldownList.Add(salesperson);
  
  
              try
              {
                  ViewData1 vData = new ViewData1();
                  DataSet ds1 = vData.__getProdOverviewDataSet(__getConnectionString());
                  DataSet ds2 = vData.__getCustOverviewDataSet(__getConnectionString());
                  DataSet ds3 = vData.__getSalesOverviewDataSet(__getConnectionString());
                  DataSet ds4 = vData.__getManOverviewDataSet(__getConnectionString());
                  DataSet ds5 = vData.__getBookedDateDataSet(__getConnectionString());
  
                  List&lt;DateTime&gt; booked_date = new List&lt;DateTime&gt;();
  
                  if (ds5.Tables[0].Rows.Count &gt; 0)
                  {
                      foreach (DataRow row in ds5.Tables[0].Rows)
                      {
                          if (row[0].ToString() != " " &amp;&amp; row[0] != null)
                          {
                              booked_date.Add(Convert.ToDateTime(row[0]));
                          }
                      }
                  }
                  booked_date.Remove(Convert.ToDateTime("1/1/0001 12:00:00 AM"));
                  booked_date.Sort();
                  ArrayList daterange = new ArrayList();
                  daterange = _getDateRange();
                  if (Convert.ToDateTime(daterange[0]) &gt; Convert.ToDateTime(daterange[1]))
                  {
                   //   DataGrid1.Visible = false;
                   //   Label4.Visible = false;
                  //    TxtCustProd.Visible = false;
                  //    Panel1.Visible = false;
                  //    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "&lt;script&gt;alert('There is no data found')&lt;/script&gt;");
                  //    return;
                  }
                  if (ToDateTxtBox.Text != "" &amp;&amp; ToDateTxtBox.Text != "To Date" &amp;&amp; FromDateTxtBox.Text != "From Date")
                  {
                      DropDownList2.Text = "Months";
                      DropDownList3.Text = "Years";
                      if (!booked_date.Contains(Convert.ToDateTime(daterange[2])) &amp;&amp; !booked_date.Contains(Convert.ToDateTime(daterange[3])))
                      {
                       //   DataGrid1.Visible = false;
                       //   Label4.Visible = false;
                      //    TxtCustProd.Visible = false;
                      //    Panel1.Visible = false;
                      //    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "&lt;script&gt;alert('There is no data found')&lt;/script&gt;");
                      }
                  }
                  else
                  {
                      ToDateTxtBox.Text = "";
                      FromDateTxtBox.Text = "";
                  }
  
  
  
  
                  int countCustomer = -1;
                  int countProduct = -1;
                  int countSales = -1;
                  int countMan = -1;
                  if (ds1.Tables[0].Rows.Count &gt; 0)
                  {
                      countProduct = ds1.Tables[0].Rows.Count;
                  }
                  if (ds2.Tables[0].Rows.Count &gt; 0)
                  {
                      countCustomer = ds2.Tables[0].Rows.Count;
                  }
                  if (ds3.Tables[0].Rows.Count &gt; 0)
                  {
                      countSales = ds3.Tables[0].Rows.Count;
                  }
                  if (ds4.Tables[0].Rows.Count &gt; 0)
                  {
                      countMan = ds4.Tables[0].Rows.Count;
                  }
  
  
                  System.Data.DataTable dt = new System.Data.DataTable();
                  string test = "";
                  if(Session["callcount"] != null){
                      string coo = Session["callcount"].ToString(); 
                      int coi = Int16.Parse(coo);
                      Session["callcount"] = coi + 1;
                      test = Session["callcount"].ToString();
                  }
                  else{
                      int coi = 0;
                      Session["callcount"] = coi.ToString();
                      test = Session["callcount"].ToString();
                  }
                  dt = vData.__getProductLevelSource(__getConnectionString(), __getDropDownValues(), __getProdFilterValues(), __getCustFilterValues(), __getSalesFilterValues(), __getManFilterValues(), countCustomer, countProduct, countSales, countMan, _getDateRange(), __getProdFamilyFilterValues(), productDrilldownList);
                  GridView1.DataSource = dt;
                  GridView1.DataBind();
                  //dt.Rows.Count
                  Gridview_Columnshide(GridView1);
              }
              catch (Exception dateerr)
              {
                  //DataGrid1.Visible = false;
                  //Label4.Visible = false;
                  //TxtCustProd.Visible = false;
                  //Panel1.Visible = false;
                  //ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "&lt;script&gt;alert('There is no data found')&lt;/script&gt;");
  
              }
  
              ModalPopupExtender1.Show();
              //UpdatePanel3.Update();
  
          }
  </code></pre>