2015-09-24 65 views
1

我有一個GridView控件,並且在此控件的內部,我使用GridView.ItemTemplate定義了一個鏈接按鈕。在GridView中單擊LinkBut​​ton時避免頁面刷新

我正在使用它打開一個新窗口點擊。然而,當我點擊鏈接按鈕時,頁面在打開新窗口之前刷新。

如何在鏈接按鈕被點擊後停止刷新頁面?

HTML

 <asp:UpdatePanel ID="UpdatePanel4" runat="server"> 
       <ContentTemplate> 

           <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" > 
             <HeaderStyle Font-Names="Arial;" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="White" Font-Bold="True" Height="20" BackColor="#298DC7" ></HeaderStyle> 
<asp:templatefield headertext="NDC" ItemStyle-CssClass="col" ItemStyle-HorizontalAlign="Justify" HeaderStyle-Width="10%" ItemStyle-Width="10%">          <Columns>    
      <itemtemplate> 
      <asp:linkbutton id="productcode" ForeColor="#09538A" runat="server" text='<%#Eval("product code")%>'></asp:linkbutton>        

              </itemtemplate> 
           </asp:templatefield> 
      </asp:GridView> 
         </ContentTemplate> 
     </asp:UpdatePanel> 


           <AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" CancelControlID="cancel" TargetControlID="Button3" runat="server" PopupControlID="pnlpopup"> </AjaxToolkit:ModalPopupExtender> 

      <asp:Button ID="Button3" runat="server" style="visibility:hidden" Text="Button" /> 
        <asp:Panel ID="pnlpopup" CssClass="PanelPopup" runat="server"> 
           <div style="width:inherit;text-align:center;">Products of <%=ndc %> Product Family</div> 
           <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" > 
            <HeaderStyle Height="10%" CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="true" BackColor="#298DC7"></HeaderStyle> 
            <rowstyle Height="20px" /> 
       <alternatingrowstyle Height="20px"/> 
            <Columns> 
     <asp:boundfield datafield="product code" sortexpression="customers " ItemStyle-CssClass="col" headertext="NDC"/> 

    <div id="div<%# Convert.ToString(Eval("customer"))+ Convert.ToString(Eval("ManufacturingPartner"))+ Convert.ToString(Eval("product code"))+ Convert.ToString(Eval("Sales Person")) %>" style="display: none; position: relative; left: 15px; overflow: auto"> 
           <asp:GridView ID="gvOrderInfo" runat="server" ForeColor="#09538A" AutoGenerateColumns="false" BorderStyle="Double" BorderColor="#df5015" Width="500px" OnRowDataBound="gvOrderInfo_RowDatabound"> 
           <HeaderStyle CssClass="MyHeaderStyle" Font-Size="13px" ForeColor="#FFFFFF" Font-Bold="True" BackColor="#298DC7"></HeaderStyle> 
           <RowStyle BackColor="#E1E1E1" /> 
           <AlternatingRowStyle BackColor="White" /> 
           <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" /> 
           <Columns> 
     <asp:BoundField DataField="Order Number" HeaderText="Order Number" ItemStyle-Width="75px" ItemStyle-CssClass="col" HeaderStyle-HorizontalAlign="Left" /> 
      </Columns> 
     </Columns>        
           </asp:GridView> 
          </div>       
            </asp:GridView> 
    </asp:Panel> 

代碼隱藏

protected void DataGrid1__RowDataBound(Object sender, GridViewRowEventArgs e) 
{  
    this.UpdatePanel4.Update(); 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
      LinkButton lnk = e.Row.FindControl("ppp") 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 > 0) 
       //if (DataGrid1.Columns[0].Visible == true) 
       { 
       }    
      } 
    } 
} 
+0

對於指定了OnClientClick事件的行。嘗試使用OnClientClick =「返回false;」 –

+0

你好我試過了不行 – user2181338

+0

請發帖整個頁面的代碼。它會更容易在我的身邊重現 –

回答

0

我不會用一個LinkBut​​ton,但直HTML鏈接。

<ContentTemplate> 
    <a href="#" ID='<%#Eval("product code")%>' onclick="doSomething();"> 
     <%#Eval("productcode")%> 
    </a> 
</ContentTemplate> 

然後你可以在頁面中定義一些javascript。

function doSomething(ProductCode) { 
    // enter the code here to open the window 
} 

此外,我會遠離使用UpdatePanel,但這只是我的偏好。

相關問題