避免在每个页面加载上回发主页用户控件 [英] Avoid postbacking masterpage user control on every pageload

查看:78
本文介绍了避免在每个页面加载上回发主页用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个多用户应用程序,其中每个用户都有一组要访问的webforms并且不使用特定的设置(几乎30种类型的配置文件)



我创建了两个表Menu Master和Sub菜单master和添加的url以及父子关系



我在用户控件中使用Infragistic WebExplorer作为导航控件而我我正在进行Usercontrol代码隐藏中的所有数据绑定。



我的问题是每次用户单击WebExplorer时控件获得数据绑定并重新呈现控件。导致应用程序非常慢任何人都可以建议我如何在每次回发时避免这种数据绑定



我尝试过:



I am creating an multi user application where each user have a set of webforms to be accessed and specific set not to be used(almost 30 types of profiles)

I had created two tables Menu Master and Sub menu master and Added urls and the parent child relation

I am using a Infragistic WebExplorer as Navigation control inside a usercontrol and I am doing all the data binding inside the Usercontrol codebehind.

My issue is each time when a user click the WebExplorer the control get databinded and the control is re rendered. causing application very slow Can anyone suggest me how to avoid this data binding on each postback

What I have tried:

    public partial class MyMenuBar : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {           
                loadexplorerebar();          

        }



        public void getMenuData()
        {
            SqlCommand cmd = new SqlCommand("select * from MainMenuMaster");

            DataTable dt = ReturnQueryResultDatatable(cmd);

            SqlCommand cmd1 = new SqlCommand(@"SELECT        SubMenuMaster.Menu_PK, SubMenuMaster.MenuText, SubMenuMaster.MenuURL, SubMenuMaster.ParentID, SubMenuMaster.isEnable, SubMenuMaster.IsNormal
FROM            SubMenuMaster INNER JOIN
                         UserProfileRights ON SubMenuMaster.Menu_PK = UserProfileRights.Menu_PK
WHERE(UserProfileRights.UserProfile_Pk = @Param2)");
            cmd1.Parameters.AddWithValue("@Param2", int.Parse(Session["UserProfile_Pk"].ToString()));
            DataTable dt2 = ReturnQueryResultDatatable(cmd1);
            Session["MainMenuMaster"] = dt;
            Session["SubMenuMaster"] = dt2;

        }


        public void loadexplorerebar()
        {
            DataTable dt = null;
            DataTable dt2 = null;

            if (Session["MainMenuMaster"]==null || Session["SubMenuMaster"]==null)
            {
                getMenuData();
            }
            else
            {
                dt = (DataTable)Session["MainMenuMaster"];
                dt2 = (DataTable)Session["SubMenuMaster"];

            }            
                     

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ExplorerBarGroup grp = new ExplorerBarGroup();
                    grp.Text = dt.Rows[i]["MainmenuName"].ToString();
                    this.WebExplorerBar1.Groups.Add(grp);
                    int MAINMENU_PK = int.Parse(dt.Rows[i]["mAINmENU_pk"].ToString());
                    try
                    {

                        DataTable mainmenuchild = dt2.Select("parentid=" + MAINMENU_PK + "").CopyToDataTable();

                        foreach (DataRow drow in mainmenuchild.Rows)
                        {

                            int childid = int.Parse(drow["Menu_PK"].ToString());
                            ExplorerBarItem item = new ExplorerBarItem();
                            item.Text = drow["MenuText"].ToString();
                            item.NavigateUrl = drow["MenuURL"].ToString();
                            grp.Items.Add(item);
                            try
                            {
                                getnewItem(item, childid, dt2);
                            }
                            catch (Exception)
                            {


                            }
                        }
                    }
                    catch (Exception)
                    {


                    }


                }


            }

        }



        public void getnewItem(ExplorerBarItem item, int parentid, DataTable mainmenuchild)
        {
            if (parentid == 220)
            {
                int k = 0;
            }
            DataTable mainmenuchildtemp = mainmenuchild.Select("parentid=" + parentid + "").CopyToDataTable();
            foreach (DataRow drow in mainmenuchildtemp.Rows)
            {

                try
                {
                    int childid = int.Parse(drow["Menu_PK"].ToString());
                    ExplorerBarItem itemnum = new ExplorerBarItem();
                    itemnum.Text = drow["MenuText"].ToString();
                    itemnum.NavigateUrl = drow["MenuURL"].ToString();
                    item.Items.Add(itemnum);
                    getnewItem(itemnum, childid, mainmenuchild);
                }
                catch (Exception)
                {
                    ;
                }
            }
        }





我的HTML标记如下所示





And My HTML markup is like below

<ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="250px">
    </ig:WebExplorerBar>

推荐答案

真实摆脱整页回发的解决方案是使用AJAX。



我建议您在专用的infragistics论坛上发布您的问题,因为您使用的是infragistics控件。这样,该论坛的专家可能会帮助您解决当前的问题。 开发人员.net论坛 - Infragistics编程论坛 - 用户界面论坛 [ ^ ]
The real solution to get rid of full page postback is to use AJAX.

I would recommend you to also post your issue at dedicated infragistics forums since you are using infragistics controls. That way experts on that forum might be able to help you on your current issue. Developers .net Forum - Infragistics Programming Forum - User Interface Forum[^]


这篇关于避免在每个页面加载上回发主页用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆