protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(Shared_Story));
        //code for YT MObile redirections
        string redirctMobileUrl = string.Empty;

        MiscellaneousController objMisc = new MiscellaneousController();
        if (!IsPostBack)
        {
            DeviceManager deviceManager = new DeviceManager
            {
                UserAgent = Request.UserAgent,
                IsMobileBrowser = Request.Browser.IsMobileDevice
            };
            if (deviceManager.IsMobileDevice())
            {
                #region MObile Redirect

                Tributes obTrb = new Tributes();
                string mTrbUrl = string.Empty;
                string mTrbType = string.Empty;
                string strStartUrl = string.Empty;
                int mTabId = 0;
                if (Request.QueryString["TributeUrl"] != null)
                {
                    obTrb.TributeUrl = mTrbUrl = Request.QueryString["TributeUrl"].ToString();
                }
                if (Request.QueryString["TributeType"] != null)
                {
                    obTrb.TypeDescription = mTrbType = Request.QueryString["TributeType"].ToString();
                }
                bool IsMobileViewOn = objMisc.GetIsMobileViewOn(obTrb);

                bool IsMobileRedirectOn = false;
                bool.TryParse(WebConfig.IsMobileRedirectOn, out IsMobileRedirectOn);

                if (!(string.IsNullOrEmpty(mTrbUrl)) && !(string.IsNullOrEmpty(mTrbType)) && IsMobileViewOn && IsMobileRedirectOn && (mTrbType.ToLower().Equals("memorial")))
                {
                    obTrb = objMisc.GetTributeUrlOnOldTributeUrl(obTrb, WebConfig.ApplicationType.ToString());

                    strStartUrl = string.Format("{0}{1}{2}{3}{4}{5}", "https://www.", WebConfig.TopLevelDomain, "/mobile/index.html?tributeurl=", obTrb.TributeUrl, "&tributetype=", mTrbType);

                    string url = Request.Url.ToString().ToLower();
                    
                    #region story
                    if (url.Contains("story.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=story"; 
                    #endregion
                    #region notes
                    else if (url.Contains("notes.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=notes"; 
                    #endregion
                    #region note
                    else if (url.Contains("notefullview.aspx"))
                    {
                        if ((Request.QueryString["noteId"] != null))
                        {
                            if (int.TryParse(Request.QueryString["noteId"], out mTabId))
                            {
                                redirctMobileUrl = strStartUrl + "&page=note&id=" + mTabId.ToString();
                            }
                            else
                            {
                                redirctMobileUrl = strStartUrl + "&page=notes";
                            }
                        }
                        else
                        {
                            redirctMobileUrl = strStartUrl + "&page=notes";
                        }
                    } 
                    #endregion
                    #region events
                    else if (url.Contains("event.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=events"; 
                    #endregion
                    #region event
                    else if (url.Contains("eventfullview.aspx"))
                    {
                        if ((Request.QueryString["EventID"] != null))
                        {
                            if (int.TryParse(Request.QueryString["EventID"], out mTabId))
                            {
                                redirctMobileUrl = strStartUrl + "&page=event&id=" + mTabId.ToString();
                            }
                            else
                            {
                                redirctMobileUrl = strStartUrl + "&page=events";
                            }
                        }
                        else
                        {
                            redirctMobileUrl = strStartUrl + "&page=events";
                        }
                    } 
                    #endregion
                    #region guestbook
                    else if (url.Contains("guestbook.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=guestbook"; 
                    #endregion
                    #region gift
                    else if (url.Contains("gift.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=memorials"; 
                    #endregion
                    #region photogallery
                    else if (url.Contains("photogallery.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=gallery"; 
                    #endregion
                    #region photoalbum
                    else if (url.Contains("photoalbum.aspx"))
                    {
                        if ((Request.QueryString["PhotoAlbumId"] != null))
                        {
                            if (int.TryParse(Request.QueryString["PhotoAlbumId"], out mTabId))
                            {
                                redirctMobileUrl = strStartUrl + "&page=photoalbum&id=" + mTabId.ToString();
                            }
                            else
                            {
                                redirctMobileUrl = strStartUrl + "&page=gallery";
                            }
                        }
                        else
                        {
                            redirctMobileUrl = strStartUrl + "&page=gallery";
                        }
                    } 
                    #endregion
                    #region photoview
                    else if (url.Contains("photoview.aspx"))
                    {
                        if ((Request.QueryString["PhotoId"] != null))
                        {
                            if (int.TryParse(Request.QueryString["PhotoId"], out mTabId))
                            {
                                redirctMobileUrl = strStartUrl + "&page=photo&id=" + mTabId.ToString();
                            }
                            else
                            {
                                redirctMobileUrl = strStartUrl + "&page=gallery";
                            }
                        }
                        else
                        {
                            redirctMobileUrl = strStartUrl + "&page=gallery";
                        }
                    } 
                    #endregion
                    #region photoview
                    else if (url.Contains("photoview.aspx"))
                        redirctMobileUrl = strStartUrl + "&page=gallery"; 
                    #endregion
                    #region managevideo
                    else if (url.ToLower().Contains("managevideo.aspx"))
                    {
                         #region videoTribute
                        if (url.ToLower().Contains("videotype=videotribute"))
                        {
                            redirctMobileUrl = string.Empty;
                        }
                        #endregion
                        else if ((Request.QueryString["videoId"] != null))
                        {
                            if (int.TryParse(Request.QueryString["videoId"], out mTabId))
                            {
                                redirctMobileUrl = strStartUrl + "&page=video&id=" + mTabId.ToString();
                            }
                            else
                            {
                                redirctMobileUrl = strStartUrl + "&page=gallery";
                            }
                        }
                        else
                        {
                            redirctMobileUrl = strStartUrl + "&page=gallery";
                        }
                    } 
                    #endregion
                    #region videos
                    else if (url.ToLower().Contains("videogallery.aspx"))
                    {
                            redirctMobileUrl = strStartUrl + "&page=gallery";
                    }
                    #endregion
                    else
                    {
                        redirctMobileUrl = strStartUrl + "&page=home";
                    }
                }
                #endregion
            }
        }
        if (string.IsNullOrEmpty(redirctMobileUrl))
        {
        try
        {

            PageUrl = GetRedirectUrl();
            PageTitle = Page.Title.ToString();
            codedURL = HttpUtility.UrlEncode(PageUrl).ToString();
            codedtitle = HttpUtility.UrlEncode(PageTitle).ToString();

            if (Request.QueryString["topurl"] != null)
            {
                _TopUrl = Request.QueryString["topurl"].ToString();
                Response.Cookies["topurl"].Value = _TopUrl;
                Response.Cookies["topurl"].Domain = _TopUrl;
                Response.Cookies["topurl"].Expires = DateTime.Now.AddHours(4);
            }

            if (Request.Cookies["topurl"] != null)
            {
                hdnTopUrl.Value = Request.Cookies["topurl"].Value.ToString();
            }
            if (Session["isInIframe"] != null)
            {
                isInIframe = bool.Parse(Session["isInIframe"].ToString());
            }

            // New code added on 07 june 2011 by rupendra to handle Apple safari problem
            if (Request.Browser.Browser.ToString().Trim().Equals("AppleMAC-Safari"))
            {
            }

            //LHK:EmptyDivAboveMainPanel
            StateManager stateTribute = StateManager.Instance;
            SessionValue objSessvalue = (SessionValue)stateTribute.Get("objSessionvalue", StateManager.State.Session);
            if ((Request.QueryString["TributeUrl"] != null))
            {
                string _trbUrl = Request.QueryString["TributeUrl"].ToString();
                GetCustomHeaderVisible(_trbUrl, WebConfig.ApplicationType.ToString());
            }
            if (!(objSessvalue != null))
            {
                if (!IsCustomHeaderOn)
                {
                    EmptyDivAboveMainPanel.Visible = true;
                }
            }
            //LHK:EmptyDivAboveMainPanel

            if (WebConfig.ApplicationMode.Equals("local"))
            {
                appDomian = WebConfig.AppBaseDomain.ToString();
            }
            else
            {
                StateManager stateManager = StateManager.Instance;
                Tributes objTrib = (Tributes)stateManager.Get("TributeSession", StateManager.State.Session);
                //Ashu 18 aug for session null
                if (objTrib != null)
                {
                    if (objTrib.TypeDescription != null)
                    {
                        appDomian = "http://" + objTrib.TypeDescription.ToString().ToLower().Replace("new baby", "newbaby") + "." + WebConfig.TopLevelDomain + "/";
                    }
                    else if (Session["PhotoAlbumTributeSession"] != null)
                    {
                        objTrib = Session["PhotoAlbumTributeSession"] as Tributes;
                        if (objTrib.TypeDescription != null)
                            appDomian = "http://" + objTrib.TypeDescription.ToString().ToLower().Replace("new baby", "newbaby") + "." + WebConfig.TopLevelDomain + "/";
                    }
                }
                else if (Session["PhotoAlbumTributeSession"] != null)
                {
                    objTrib = Session["PhotoAlbumTributeSession"] as Tributes;
                    if (objTrib != null)
                    {
                        if (objTrib.TypeDescription != null)
                            appDomian = "http://" + objTrib.TypeDescription.ToString().ToLower().Replace("new baby", "newbaby") + "." + WebConfig.TopLevelDomain + "/";
                    }
                }
            }


            try
            {
                if (Request.QueryString["TributeType"] != null)
                {
                    ytHeader.TributeType = Request.QueryString["TributeType"].ToString();
                }

                // get the Tribute and User detail from the Session           
                GetValuesFromSession();
                // Set the Class of the div according the Page Name
                SetClass();
                SetTabClass();
                // This function will set the Left Menu
                SetMenuOptions();
                SetMenuItemClass();
                // This Function will load themes in the left panel and loads the selected theme for the tribute.
                LoadThemes();
                //Method to check if tribute already in favorite list.
                CheckForFavorite();
                //to set affiliate link.
                AffiliateLinks(_tributeType);
                StateManager objStateManager = StateManager.Instance;
                if (objStateManager.Get("NoteSession", StateManager.State.Session) != null)
                    _noteId = int.Parse(objStateManager.Get("NoteSession", StateManager.State.Session).ToString());
                if (objStateManager.Get("VideoSession", StateManager.State.Session) != null)
                    _videoId = int.Parse(objStateManager.Get("VideoSession", StateManager.State.Session).ToString());
                if (objStateManager.Get("PhotoViewSession", StateManager.State.Session) != null)
                    _photoId = int.Parse(objStateManager.Get("PhotoViewSession", StateManager.State.Session).ToString());
                if (objStateManager.Get("PhotoAlbumId", StateManager.State.Session) != null)
                    _photoAlbumId = int.Parse(objStateManager.Get("PhotoAlbumId", StateManager.State.Session).ToString());
                if (objStateManager.Get("XmlFilePath", StateManager.State.Session) != null) //to get xml file name for slideshow
                    _xmlFilePath = objStateManager.Get("XmlFilePath", StateManager.State.Session).ToString();
                //to get photo number from where to start slideshow.
                if (objStateManager.Get("SlideShowStartPhoto", StateManager.State.Session) != null) //to get start photo number in slideshow.
                    _recordNumber = int.Parse(objStateManager.Get("SlideShowStartPhoto", StateManager.State.Session).ToString());
                else
                    _recordNumber = 0;

                // Set the controls value
                SetControlsValue();



                SetPageNameInSession(_typeName);
                if (!(string.IsNullOrEmpty(_tributeType)))
                {
                    if (_tributeType == "Anniversary")
                        _themeName = "AnniversaryDefault";
                    else if (_tributeType == "Birthday")
                        _themeName = "BirthdayDefault";
                    else if (_tributeType == "Graduation")
                        _themeName = "GraduationDefault";
                    else if (_tributeType == "Memorial")
                        _themeName = "MemorialDefault";
                    else if (_tributeType == "New Baby")
                        _themeName = "BabyDefault";
                    else if (_tributeType == "Wedding")
                        _themeName = "WeddingDefault";
                }

                //LHK: for photo upgrade changes
                if ((liAdd.Visible == false) && (liEdit.Visible == false) && (liView.Visible == false) && (liDownloadalbum.Visible == false) && (liVieFullPhoto.Visible == false))
                    divSubTool.Visible = false;
            }
            catch (Exception ex)
            {
                LogError(ex.Message, ex.StackTrace);
                throw ex;
            }
        }
        catch (Exception ex)
        {
            LogError(ex.Message, ex.StackTrace);
            throw ex;
        }
        }
        else
        {
            Response.Redirect(redirctMobileUrl, false);
        }
    }