【问题标题】:panel popup is taking more time to close on click of close button in panel [duplicate]单击面板中的关闭按钮时,面板弹出窗口需要更多时间来关闭[重复]
【发布时间】:2015-10-08 22:19:42
【问题描述】:

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

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

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

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

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

我需要在不刷新网格的情况下打开一个弹出窗口

请帮我找到解决方案,因为我过去 2 天一直在处理这个问题

HTML

<%@ 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();

        }

【问题讨论】:

  • 您可以在 aspx 和 c# 文件中发布您项目中的正确代码吗?您发布的那些代码没有任何意义,productcode LinkBut​​ton 没有任何 onclick 事件...很多控件没有结束标记...同样的想法是:将所有内容放在页面中updatepanel,但我们会在您更新代码后看到
  • 问题是我在回发中绑定了网格所以在我的页面加载中我有这样的代码 if(!IsPostBack){ } Gridbind();因此,这需要解决方案令人耳目一新。根据我的要求,我还需要在回发中绑定网格
  • 当你在线时给我发电子邮件:gmail 的 julyzerg13,如果你愿意,我会通过 team-viewer 帮助你。

标签: c# html .net webforms


【解决方案1】:

这里的结构:

首先,将其放在页面顶部,如果您使用的是母版页,则在 ContentPlaceHolder1 下方;如果您不使用,则将其放在表单标签下方

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

接下来,我们创建一个 UpdatePanel,页面中的所有内容都将放在该 UpdatePanel 内(您可以有其他 UpdatePanel,但这是外部的)这将确保页面不会在任何点击事件时刷新/重新加载(@此外部 UpdatePanel 不需要 987654323@)。使用 HiddenField 代替按钮的 ModalPopupExtender 的 TargetCONtrolID。

<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>

不要使用 UpdatePanel.Update() 函数,如果你想更新你的 gridview,更新你的数据集并调用 Gridview.Databind() 方法。

如果您想在 ModalPopupExtender 中使用其他 UpdatePanel,只需将所有内容都放在 Panel 中,但这次您需要 &lt;Triggers&gt; 用于此 UpdatePanel 中的按钮(而不是取消/关闭弹出按钮)

【讨论】:

  • 它停止重新加载网格,但弹出窗口未显示在链接按钮的 clcik 上
  • 只需复制并粘贴此处的所有代码,我们将看看那里发生了什么。
【解决方案2】:

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

DataGrid1.DataSource = ...;DataGrid1.DataBind(); 结合使用会将网格视图中的所有值更新为已定义列表中的值。

这意味着当您在 onPage_Load() 中有此内容时,它将刷新网格视图。

【讨论】:

  • 我在回发后也绑定了网格,就像 if(!ispostback{ } bindgrid(); 根据我的要求
  • 所以你想有时在页面重新加载时更新它,有时不?
  • 是的,你是对的
  • 整个页面在点击链接按钮时重新加载,如果我不使用更新面板,则会显示弹出窗口,如果我使用更新面板页面不刷新但不显示弹出窗口
  • 我不知道该怎么做,所以我不能再帮你了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多