private void BindModuleControls()
        {
            string          preFix       = string.Empty;
            string          paneName     = string.Empty;
            string          ControlSrc   = string.Empty;
            string          phdContainer = string.Empty;
            string          PageSEOName  = string.Empty;
            SageUserControl suc          = new SageUserControl();

            if (PagePath != null)
            {
                suc.PagePath = PagePath;
            }
            else
            {
                SageFrameConfig sfConfig = new SageFrameConfig();
                suc.PagePath = sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage);
            }
            if (PagePath != null)
            {
                PageSEOName = GetPageSEOName(PagePath);
            }
            else
            {
                SageFrameConfig sfConfig = new SageFrameConfig();
                PageSEOName = GetPageSEOName(sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage));
            }
            PageSEOName = PageSEOName.Replace("-and-", "&").Replace(" ", "-");

            //:TODO: Need to get controlType and pageID from the selected page from routing path
            //string controlType = "0";
            //string pageID = "2";
            StringBuilder redirecPath = new StringBuilder();

            if (PageSEOName != string.Empty)
            {
                SageFrameConfig       sfConfig       = new SageFrameConfig();
                string                SEOName        = sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage).Replace(" ", "-");
                List <UserModuleInfo> lstUserModules = new List <UserModuleInfo>();
                bool SuperRole = false;
                if (Session[SessionKeys.SageRoles] != string.Empty && Session[SessionKeys.SageRoles] != null)
                {
                    string[] objRole = Session[SessionKeys.SageRoles].ToString().Split(',');
                    foreach (string role in objRole)
                    {
                        if (role.Replace(" ", string.Empty).ToLower().Equals(ApplicationKeys.Super_User.ToLower().Replace("-", string.Empty)))
                        {
                            SuperRole = true;
                        }
                    }
                }
                if (GetUsername.Equals(ApplicationKeys.anonymousUser))
                {
                    lstUserModules = sfConfig.GetPageModules_Anonymous("1", PageSEOName, GetUsername, GetCurrentCulture());
                }
                else if (SuperRole)
                {
                    lstUserModules = sfConfig.GetPageModules_Superuser("1", PageSEOName, GetUsername, GetCurrentCulture());
                }
                else
                {
                    lstUserModules = sfConfig.GetPageModules("1", PageSEOName, GetUsername, GetCurrentCulture());
                }
                Uri url = HttpContext.Current.Request.Url;
                if (lstUserModules[0].IsPageAvailable)
                {
                    if (lstUserModules[0].IsPageAccessible)
                    {
                        #region "Load Controls"

                        if (lstUserModules.Count > 0)
                        {
                            OverridePageInfo(lstUserModules[0]);
                            int i = 0;
                            foreach (UserModuleInfo usermodule in lstUserModules)
                            {
                                bool handheld_status = bool.Parse(usermodule.IsHandHeld.ToString());
                                if (IsHandheld() == handheld_status)
                                {
                                    paneName = usermodule.PaneName;
                                    paneName = "pch_" + paneName;
                                    if (string.IsNullOrEmpty(paneName))
                                    {
                                        paneName = "ContentPane";
                                    }
                                    string UserModuleTitle = usermodule.UserModuleTitle != string.Empty ? usermodule.UserModuleTitle.ToString() : string.Empty;

                                    ControlSrc = usermodule.ControlSrc;
                                    string SupportsPartialRendering = usermodule.SupportsPartialRendering.ToString();

                                    string      SuffixClass    = usermodule.SuffixClass.ToString();
                                    string      HeaderText     = usermodule.ShowHeaderText ? usermodule.HeaderText : "";
                                    bool        ContainsEdit   = usermodule.IsEdit;
                                    int         ControlCount   = usermodule.ControlsCount;
                                    UserControl uc             = pchWhole.FindControl("lytA") as UserControl;
                                    PlaceHolder phdPlaceHolder = uc.FindControl(paneName) as PlaceHolder;
                                    SuffixClass = IsUserLoggedIn() && ContainsEdit?string.Format("sfLogged sfModule{0}", SuffixClass) : string.Format("sfModule{0}", SuffixClass);

                                    if (phdPlaceHolder != null)
                                    {
                                        string TemplateControls = Server.MapPath(string.Format("~/Templates/{0}/modules/{1}", activeTemplate, ControlSrc.Substring(ControlSrc.IndexOf('/'), ControlSrc.Length - ControlSrc.IndexOf('/'))));
                                        ControlSrc     = File.Exists(TemplateControls) ? string.Format("/Templates/{0}/modules/{1}", activeTemplate, ControlSrc.Substring(ControlSrc.IndexOf('/'), ControlSrc.Length - ControlSrc.IndexOf('/'))) : string.Format("/{0}", ControlSrc);
                                        phdPlaceHolder = LoadControl(i.ToString(), bool.Parse(SupportsPartialRendering), phdPlaceHolder, ControlSrc, paneName, usermodule.UserModuleID.ToString(), SuffixClass, HeaderText, IsUserLoggedIn(), GetModuleControls(usermodule.UserModuleID, ContainsEdit, ControlCount), GetPaneNameContainer(UserModuleTitle), ContainsEdit);
                                    }
                                    i++;
                                }
                            }
                        }

                        #endregion
                        else
                        {
                            if (currentportalID > 1)
                            {
                                redirecPath.Append(url.Scheme);
                                redirecPath.Append("://");
                                redirecPath.Append(url.Authority);
                                redirecPath.Append(PortalAPI.GetApplicationName);
                                redirecPath.Append("/portal/");
                                redirecPath.Append(GetPortalSEOName);
                                redirecPath.Append("/");
                                redirecPath.Append(PortalAPI.PageNotFoundPageWithExtension);
                            }
                            else
                            {
                                redirecPath.Append(url.Scheme);
                                redirecPath.Append("://");
                                redirecPath.Append(url.Authority);
                                redirecPath.Append(PortalAPI.PageNotFoundURL);
                            }

                            Response.Redirect(redirecPath.ToString());
                        }
                    }
                    else
                    {
                        if (currentportalID > 1)
                        {
                            redirecPath.Append(url.Scheme);
                            redirecPath.Append("://");
                            redirecPath.Append(url.Authority);
                            redirecPath.Append(PortalAPI.GetApplicationName);
                            redirecPath.Append("/portal/");
                            redirecPath.Append(GetPortalSEOName);
                            redirecPath.Append("/");
                            redirecPath.Append(PortalAPI.PageNotAccessiblePageWithExtension);
                        }
                        else
                        {
                            redirecPath.Append(url.Scheme);
                            redirecPath.Append("://");
                            redirecPath.Append(url.Authority);
                            redirecPath.Append(PortalAPI.PageNotAccessibleURL);
                        }
                        Response.Redirect(redirecPath.ToString());
                    }
                }
                else
                {
                    //page is not found
                    if (currentportalID > 1)
                    {
                        redirecPath.Append(url.Scheme);
                        redirecPath.Append("://");
                        redirecPath.Append(url.Authority);
                        redirecPath.Append(PortalAPI.GetApplicationName);
                        redirecPath.Append("/portal/");
                        redirecPath.Append(GetPortalSEOName);
                        redirecPath.Append("/");
                        redirecPath.Append(PortalAPI.PageNotFoundPageWithExtension);
                    }
                    else
                    {
                        redirecPath.Append(url.Scheme);
                        redirecPath.Append("://");
                        redirecPath.Append(url.Authority);
                        redirecPath.Append(PortalAPI.PageNotFoundURL);
                    }
                    Response.Redirect(redirecPath.ToString());
                }
            }
            SetScreenWidth();
        }
        private void BindModuleControls()
        {
            string          preFix       = string.Empty;
            string          paneName     = string.Empty;
            string          ControlSrc   = string.Empty;
            string          phdContainer = string.Empty;
            string          PageSEOName  = string.Empty;
            SageUserControl suc          = new SageUserControl();

            SageFrameConfig sfConfig          = new SageFrameConfig();
            string          portalDefaultPage = sfConfig.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage);

            if (PagePath != null)
            {
                suc.PagePath = PagePath;
            }
            else
            {
                suc.PagePath = portalDefaultPage;
            }
            if (PagePath != null)
            {
                PageSEOName = GetPageSEOName(PagePath);
            }
            else
            {
                PageSEOName = GetPageSEOName(portalDefaultPage);
            }
            PageSEOName = PageSEOName.Replace(" ", "-");

            //:TODO: Need to get controlType and pageID from the selected page from routing path
            //string controlType = "0";
            //string pageID = "2";
            StringBuilder redirecPath = new StringBuilder();

            if (PageSEOName != string.Empty)
            {
                RoleController        _role = new RoleController();
                bool                  isDashboardAccessible = _role.IsDashboardAccesible(GetUsername, GetPortalID);
                string                SEOName        = portalDefaultPage.Replace(" ", "-");
                List <UserModuleInfo> lstUserModules = new List <UserModuleInfo>();
                bool                  SuperRole      = false;
                string                previewCode    = "none";
                bool                  isPreview      = false;
                if (Request.QueryString["preview"] != null)
                {
                    previewCode = Request.QueryString["preview"].ToString();
                    isPreview   = true;
                }

                if (Session[SessionKeys.SageRoles] != null && Session[SessionKeys.SageRoles].ToString() != string.Empty)
                {
                    string[] objRole = Session[SessionKeys.SageRoles].ToString().Split(',');
                    foreach (string role in objRole)
                    {
                        if (role.Replace(" ", string.Empty).ToLower().Equals(ApplicationKeys.Super_User.ToLower().Replace("-", string.Empty)))
                        {
                            SuperRole = true;
                        }
                    }
                }
                if (GetUsername.Equals(ApplicationKeys.anonymousUser))
                {
                    lstUserModules = sfConfig.GetPageModules_Anonymous("1", PageSEOName, GetUsername, GetCurrentCulture());
                }
                else if (SuperRole)
                {
                    lstUserModules = sfConfig.GetPageModules_Superuser("1", PageSEOName, GetUsername, GetCurrentCulture(), isPreview, previewCode);
                }
                else
                {
                    lstUserModules = sfConfig.GetPageModules("1", PageSEOName, GetUsername, GetCurrentCulture(), isPreview, previewCode);
                }
                Uri url = HttpContext.Current.Request.Url;
                if (lstUserModules[0].IsPageAvailable)
                {
                    if (lstUserModules[0].IsPageAccessible)
                    {
                        #region "Load Controls"
                        AddMetaTag(lstUserModules[0].MetaTag);
                        if (lstUserModules.Count > 0)
                        {
                            OverridePageInfo(lstUserModules[0]);
                            bool          isUserLoggedIn  = IsUserLoggedIn();
                            List <string> moduleDefIDList = new List <string>();
                            if (isUserLoggedIn)
                            {
                                SecurityPolicy objSecurity = new SecurityPolicy();
                                objSecurity.UpdateExpireTime(GetUsername, GetPortalID);
                                moduleDefIDList.Add("-1,");
                            }
                            bool isHandheld = IsHandheld();

                            //bool gotExtraModule = false;
                            //int count = 0;
                            foreach (UserModuleInfo usermodule in lstUserModules)
                            {
                                bool handheld_status = bool.Parse(usermodule.IsHandHeld.ToString());
                                if (isHandheld == handheld_status)
                                {
                                    int pageID = lstUserModules[0].PageID;
                                    paneName = usermodule.PaneName;
                                    paneName = "pch_" + paneName;
                                    if (string.IsNullOrEmpty(paneName))
                                    {
                                        paneName = "ContentPane";
                                    }
                                    string UserModuleTitle = usermodule.UserModuleTitle != string.Empty ? usermodule.UserModuleTitle.ToString() : string.Empty;
                                    ControlSrc = usermodule.ControlSrc;
                                    string      SupportsPartialRendering = usermodule.SupportsPartialRendering.ToString();
                                    string      SuffixClass    = usermodule.SuffixClass.ToString();
                                    string      HeaderText     = usermodule.ShowHeaderText ? usermodule.HeaderText : "";
                                    bool        ContainsEdit   = usermodule.IsEdit;
                                    int         ControlCount   = usermodule.ControlsCount;
                                    UserControl uc             = pchWhole.FindControl("lytA") as UserControl;
                                    PlaceHolder phdPlaceHolder = uc.FindControl(paneName) as PlaceHolder;
                                    SuffixClass = isUserLoggedIn && ContainsEdit?string.Format("sfLogged sfModule{0}", SuffixClass) : string.Format("sfModule{0}", SuffixClass);

                                    Page page = this.Page;
                                    //if (phdPlaceHolder == null && isUserLoggedIn && isDashboardAccessible)
                                    //{
                                    //    HtmlGenericControl divWrapper = new HtmlGenericControl("div");
                                    //    divWrapper.Attributes.Add("data-usemoduleid", usermodule.UserModuleID.ToString());
                                    //    divWrapper.Attributes.Add("data-pageid", pageID.ToString());
                                    //    divWrapper.Attributes.Add("data-moduledefid", usermodule.ModuleDefID.ToString());
                                    //    divWrapper.Attributes.Add("class", "extramodule");

                                    //    phdPlaceHolder = pchAddedControl.FindControl(paneName) as PlaceHolder;
                                    //    if (phdPlaceHolder != null)
                                    //    {
                                    //        count++;
                                    //        paneName = paneName + count;
                                    //    }
                                    //    PlaceHolder ph = new PlaceHolder();
                                    //    ph.ID = paneName;
                                    //    divWrapper.Controls.Add(ph);
                                    //    pchAddedControl.Controls.Add(divWrapper);
                                    //    phdPlaceHolder = ph;
                                    //    gotExtraModule = true;
                                    //}
                                    if (phdPlaceHolder != null)
                                    {
                                        string TemplateControls = Server.MapPath(string.Format("~/Templates/{0}/modules/{1}", activeTemplate, ControlSrc.Substring(ControlSrc.IndexOf('/'), ControlSrc.Length - ControlSrc.IndexOf('/'))));
                                        ControlSrc = File.Exists(TemplateControls) ? string.Format("/Templates/{0}/modules/{1}", activeTemplate, ControlSrc.Substring(ControlSrc.IndexOf('/'), ControlSrc.Length - ControlSrc.IndexOf('/'))) : string.Format("/{0}", ControlSrc);
                                        LoadControl(phdPlaceHolder, ControlSrc, paneName, usermodule.UserModuleID.ToString(), SuffixClass, HeaderText, isUserLoggedIn, GetModuleControls(usermodule.UserModuleID, ContainsEdit, ControlCount, usermodule.ModuleDefID, pageID), GetPaneNameContainer(UserModuleTitle), ContainsEdit, ParamCollection);
                                        //changecss 1 take module list here take usermodulename
                                        moduleDefIDList.Add(usermodule.ModuleDefID.ToString());
                                    }
                                }
                            }
                            SetModuleDefList(moduleDefIDList);
                            //if (gotExtraModule)
                            //{
                            //    ExtraModuleMessage(PageSEOName);
                            //}
                        }

                        #endregion
                        else
                        {
                            if (!IsParent)
                            {
                                redirecPath.Append(url.Scheme);
                                redirecPath.Append("://");
                                redirecPath.Append(url.Authority);
                                redirecPath.Append(PortalAPI.GetApplicationName);
                                redirecPath.Append("/portal/");
                                redirecPath.Append(GetPortalSEOName);
                                redirecPath.Append("/");
                                redirecPath.Append(PortalAPI.PageNotFoundPageWithExtension);
                            }
                            else
                            {
                                redirecPath.Append(url.Scheme);
                                redirecPath.Append("://");
                                redirecPath.Append(url.Authority);
                                redirecPath.Append(PortalAPI.LoginURL);
                            }

                            Response.Redirect(redirecPath.ToString());
                        }
                    }
                    else
                    {
                        if (!IsParent)
                        {
                            redirecPath.Append(url.Scheme);
                            redirecPath.Append("://");
                            redirecPath.Append(url.Authority);
                            redirecPath.Append(PortalAPI.GetApplicationName);
                            redirecPath.Append("/portal/");
                            redirecPath.Append(GetPortalSEOName);
                            redirecPath.Append("/");
                            redirecPath.Append(PortalAPI.PageNotAccessiblePageWithExtension);
                        }
                        else
                        {
                            redirecPath.Append(url.Scheme);
                            redirecPath.Append("://");
                            redirecPath.Append(url.Authority);
                            redirecPath.Append(PortalAPI.LoginURL);
                        }
                        Response.Redirect(redirecPath.ToString());
                    }
                }
                else
                {
                    //page is not found
                    if (!IsParent)
                    {
                        redirecPath.Append(url.Scheme);
                        redirecPath.Append("://");
                        redirecPath.Append(url.Authority);
                        redirecPath.Append(PortalAPI.GetApplicationName);
                        redirecPath.Append("/portal/");
                        redirecPath.Append(GetPortalSEOName);
                        redirecPath.Append("/");
                        redirecPath.Append(PortalAPI.PageNotFoundPageWithExtension);
                    }
                    else
                    {
                        redirecPath.Append(url.Scheme);
                        redirecPath.Append("://");
                        redirecPath.Append(url.Authority);
                        redirecPath.Append(PortalAPI.LoginURL);
                    }
                    Response.Redirect(redirecPath.ToString());
                }
            }
            SetScreenWidth(GetUsername);
        }