面板弹出需要更多的时间来关闭点击面板中的关闭按钮

本文关键字:关闭按钮 时间 | 更新日期: 2023-09-27 18:15:40

我有一个GridView控件,在这个控件中我使用GridView.ItemTemplate定义了一个链接按钮。

我用这个打开一个新的窗口点击。但是,当我点击链接按钮时,在打开新窗口之前页面会刷新。

单击链接按钮后,如何阻止页面刷新?

当我将更新面板添加到第一个网格时,弹出窗口不显示

如果我从第一个网格中删除更新面板,网格正在刷新,弹出窗口显示

我需要打开一个弹出窗口而不刷新我的网格

请为我找到解决这个问题的方法,因为我从过去的2天里一直在做这个

<%@ Page Language="c#" AutoEventWireup="false" CodeFile="ViewData1.aspx.cs" Inherits="ablesas.ViewDataUI1" EnableEventValidation="false"%>

            <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:Panel id="Panel1"  runat="server" Height="30px" Width="600px">
    </asp:Panel>        
                   <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("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 > 0)
                    //if (DataGrid1.Columns[0].Visible == true)
                    {
                    }              
              }
         }
    }
后台代码>

 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<DateTime> booked_date = new List<DateTime>();
                if (ds5.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds5.Tables[0].Rows)
                    {
                        if (row[0].ToString() != " " && 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]) > Convert.ToDateTime(daterange[1]))
                {
                 //   DataGrid1.Visible = false;
                 //   Label4.Visible = false;
                //    TxtCustProd.Visible = false;
                //    Panel1.Visible = false;
                //    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('There is no data found')</script>");
                //    return;
                }
                if (ToDateTxtBox.Text != "" && ToDateTxtBox.Text != "To Date" && FromDateTxtBox.Text != "From Date")
                {
                    DropDownList2.Text = "Months";
                    DropDownList3.Text = "Years";
                    if (!booked_date.Contains(Convert.ToDateTime(daterange[2])) && !booked_date.Contains(Convert.ToDateTime(daterange[3])))
                    {
                     //   DataGrid1.Visible = false;
                     //   Label4.Visible = false;
                    //    TxtCustProd.Visible = false;
                    //    Panel1.Visible = false;
                    //    ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('There is no data found')</script>");
                    }
                }
                else
                {
                    ToDateTxtBox.Text = "";
                    FromDateTxtBox.Text = "";
                }


                int countCustomer = -1;
                int countProduct = -1;
                int countSales = -1;
                int countMan = -1;
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    countProduct = ds1.Tables[0].Rows.Count;
                }
                if (ds2.Tables[0].Rows.Count > 0)
                {
                    countCustomer = ds2.Tables[0].Rows.Count;
                }
                if (ds3.Tables[0].Rows.Count > 0)
                {
                    countSales = ds3.Tables[0].Rows.Count;
                }
                if (ds4.Tables[0].Rows.Count > 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", "<script>alert('There is no data found')</script>");
            }
            ModalPopupExtender1.Show();
            //UpdatePanel3.Update();
        }

面板弹出需要更多的时间来关闭点击面板中的关闭按钮

结构如下:

首先,把它放在你的页面的顶部,在ContentPlaceHolder1的右边如果你使用的是母版或者在form标签的右边如果你不是

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>

接下来,我们创建一个UpdatePanel,页面中的所有内容都将放在这个UpdatePanel中(您可以拥有其他UpdatePanel,但这是外部的),这将确保页面不会在任何单击事件上刷新/重新加载(<trigger>不需要这个外部UpdatePanel)。使用HiddenField的TargetCOntrolID的ModalPopupExternder代替按钮。

<asp:UpdateProgress ID="UpdateProgress1" DisplayAfter="10" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
         <ProgressTemplate>
            <div style="position: absolute; visibility: visible; border: none; z-index: 100; width: 100%; height: 100%; background: #999; filter: alpha(opacity=80); -moz-opacity: .8; opacity: .8;">
                <img src="http://www.ajaxload.info/images/exemples/29.gif" style="top: 50%; left: 50%; position: relative;" />
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            //all your contents will be here
            //Your DataGrid1 with LinkButton inside...
            <AjaxToolkit:ModalPopupExtender ID="ModalPopupExtender1"   BackgroundCssClass="modalBackground" CancelControlID="cancel" TargetControlID="HiddenField1" runat="server" PopupControlID="pnlpopup"> </AjaxToolkit:ModalPopupExtender>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            // Your pnlpopup Panel
        </ContentTemplate>
        <Triggers>
        </Triggers>
    </asp:UpdatePanel>

不要使用updateppanel . update()函数,如果你想更新你的gridview,更新你的数据集并调用gridview . databind()方法。

如果你想在ModalPopupExtender中使用其他UpdatePanel,只需将所有内容放在面板中,但这次你将需要<Triggers>用于此UpdatePanel中的按钮(而不是取消/关闭弹出按钮)

检查onPage_Load()中是否有DataGrid1.DatsourceDataGrid1.Databind();因为它会在你按下按钮时被调用。

DataGrid1.DataSource = ...;DataGrid1.DataBind();结合将gridview中的所有值更新为定义列表中的值。

这意味着当你有这个在你的onPage_Load()它将刷新gridview