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)
{
;
}
}
}
And My HTML markup is like below
<ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="250px">
</ig:WebExplorerBar>