UserControl减慢了Aspx页面的速度

时间:2013-01-24 08:16:35

标签: c# asp.net user-controls code-behind webusercontrol

我有一个包含GridView的usercontrol。当我在aspx页面中使用此usercontrol时,它工作正常。但是当我在GridView中选择一行时,它的工作速度很慢。

你有什么解决方案可以让它更快吗?

1.UserControl

1.1.Html 父网格:

 <asp:GridView ID="gvChannelUC" name="gvChannelUCName" />

ChildGrid:

<asp:GridView ID="gvContentServerUC" 

1.2.CodeBehind:

PageLoad()函数

    {
//Fill data for ParentGrid
    DataTable dt = new DataTable();
                DataRow dr = null;
                dt.Columns.Add(new DataColumn("fullIndex", typeof(string)));
                dt.Columns.Add(new DataColumn("IPAddress", typeof(string)));
                dt.Columns.Add(new DataColumn("SubNetMask", typeof(string)));
                dt.Columns.Add(new DataColumn("Port", typeof(string)));
                dt.Columns.Add(new DataColumn("MaxConnect", typeof(string)));
                if (valuesUC.interfaces!=null)
                foreach (IPSInterface IPSInteface in valuesUC.interfaces)
                {
                    foreach (IPSChannel ipsChannel in IPSInteface.channels)
                    {
                        dr = dt.NewRow();
                        dr["fullIndex"] = ipsChannel.fullIndex;
                        dr["IPAddress"] = IPSInteface.LocalInterfaceIP;
                        dr["SubNetMask"] = IPSInteface.LocalInterfaceNetmask;
                        dr["Port"] = ipsChannel.localInterfacePort;
                        dr["MaxConnect"] = ipsChannel.maxConnections;
                        dt.Rows.Add(dr);
                    }
                }
                Session["dt"] = dt;
                gvChannelUC.DataSource = dt;
                gvChannelUC.DataBind();
            }
    }

//为ChildGrid填充数据

protected void gvChannelSelected()
        {
            ip = IP;
            port = Port;
            if(  (((SetupIPServicesValues)Session["values"]).interfaces)!=null)
            foreach (IPSInterface IPSInteface in ((SetupIPServicesValues)Session["values"]).interfaces)
            {
                foreach (IPSChannel ipsChannel in IPSInteface.channels)
                {
                    string fullIndexFor = null;
                    string fullIndex = null;
                    fullIndex = gvChannelUC.SelectedRow.Cells[1].Text.ToString().Trim();//=======1 mean fullIndex
                    fullIndexFor = ipsChannel.fullIndex.Trim();
                    if (fullIndex.Equals(fullIndexFor))//Compare Channel fullIndex with array
                    {
                        DataTable dtCS = null;
                        DataRow drCS = null;
                        dtCS = new DataTable();
                        dtCS.Columns.Add(new DataColumn("fullIndex", typeof(string)));
                        dtCS.Columns.Add(new DataColumn("IPAddress", typeof(string)));
                        dtCS.Columns.Add(new DataColumn("Port", typeof(string)));
                        dtCS.Columns.Add(new DataColumn("Notes", typeof(string)));
                        foreach (IPSServer ipServer in ipsChannel.servers)//Get Content Server from array to fill grid
                        {
                            drCS = dtCS.NewRow();
                            drCS["fullIndex"] = ipServer.fullIndex;
                            drCS["IPAddress"] = ipServer.address;
                            drCS["Port"] = ipServer.port;
                            drCS["Notes"] = ipServer.notes;
                            dtCS.Rows.Add(drCS);
                        }
                        Session["dtContentServer"] = dtCS;
                        gvContentServerUC.DataSource = dtCS;
                        gvContentServerUC.DataBind();

                        //Other controls                 
                        if (txtServerMonitoring.Items.Count == 0)
                            setDrdSource(txtServerMonitoring, ipsChannel.IPSMonitoringPolicyListString);
                        if (txtServerMonitoring.Items.Count != 0)
                        {
                            string valueMonitorAPI = ipsChannel.monitoringPolicy.Trim();
                            if (valueMonitorAPI == "None")
                                txtServerMonitoring.Text = "None";
                            else if (valueMonitorAPI == "Echo")
                                txtServerMonitoring.Text = "Echo";
                            else if (valueMonitorAPI == "Connect")
                                txtServerMonitoring.Text = "Connect";
                            else if (valueMonitorAPI == "0")
                                txtServerMonitoring.Text = "0";
                        }

                        if (txtLoadBalancingPolicy.Items.Count == 0)
                            setDrdSource(txtLoadBalancingPolicy, ipsChannel.IPSLoadBalancePolicyListString);
                        if (txtLoadBalancingPolicy.Items.Count != 0)
                            setLoadBalancePolicyFtp(ipsChannel.loadBalancePolicy);

                        if (txtConnectivity.Items.Count == 0)
                            setDrdSource(txtConnectivity, ipsChannel.ConnectivityListString);

                        if (txtConnectivity.Items.Count != 0)
                        {
                            string valueAPI = ipsChannel.Connectivity.Trim();
                            if (valueAPI == "managed")
                                txtConnectivity.Text = "managed";
                            else if (valueAPI == "dsr")
                                //txtConnectivity.Text = "Direct Server Return";
                                txtConnectivity.Text = "dsr";
                            else if (valueAPI == "transparency")
                                txtConnectivity.Text = "transparency";
                            else if (valueAPI == "gateway")
                                txtConnectivity.Text = "gateway";
                        }

                        if (txtCachingStrategy.Items.Count == 0)
                            setDrdSource(txtCachingStrategy, ipsChannel.IPSCachePortListString);
                        if (txtCachingStrategy.Items.Count != 0)
                            txtCachingStrategy.SelectedIndex = ipsChannel.cachePort;

                        if (txtSSL.Items.Count == 0)
                            setDrdSource(txtSSL, ipsChannel.IPSSSLCertificateListString);
                        if (txtSSL.Items.Count != 0)
                            setCertificateName(ipsChannel.certificateName);

                        if (txtContentSSL.Items.Count == 0)
                            setDrdSource(txtContentSSL, ipsChannel.IPSSSLClientCertificateListString);
                        if (txtContentSSL.Items.Count != 0)
                            setClientCertificateName(ipsChannel.ClientCertificateName);
                        //=============6 drd end
                        chkEnableConnectionPolling.Checked = ipsChannel.CSGPoolEnabled;
                        if (ipsChannel.CSGPoolSize != null)
                            txtConnectionPoolSize.Text = ipsChannel.CSGPoolSize;

                        if (txtAvailableFP.Items.Count == 0)
                            if (ipsChannel.FlightPathSelectionListString != null)
                                setDrdSource(txtAvailableFP, ipsChannel.FlightPathSelectionListString);
                        lbl.Text = ipsChannel.SelectedFPRule;
                        return;//return void after fill data to Content Server
                    }
                }
            }
        }

2.Aspx主页

2.1.Html:Place Holder用于添加动态UserControl

<asp:PlaceHolder ID="phDevices" runat="server" >
                                            </asp:PlaceHolder>

代码隐藏:

PageLoad()函数:

//Add more dynamic UserControl to PlaceHolder
    foreach (DataRow row in dtDevicesListByRole.Rows)
                {
                wuc[i] = (Test2.SetupGroup.Ipservice.IpInterfaceUC)LoadControl("IpInterfaceUC.ascx");
    }

如果您需要详细信息,我会添加更多。谢谢

0 个答案:

没有答案