我正在创建一个多用户应用程序,其中每个用户都有一组要访问的webforms并且不使用特定的设置(近30种类型的配置文件)
我创建了两个表Menu Master和Sub menu master以及添加的url和父子关系
我在用户控件中使用Infragistic WebExplorer作为导航控件,我在Usercontrol代码隐藏中进行所有数据绑定。
我的问题是,每当用户单击WebExplorer时控件获得数据绑定并重新呈现控件。导致应用程序非常慢
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("", 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)
{
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标记如下所示
<ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="250px">
</ig:WebExplorerBar>
任何人都可以建议我如何避免每次回发的数据绑定
答案 0 :(得分:0)
放置你的loadexplorerebar();方法内!的IsPostBack
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadexplorerebar();
}
}