Page losing title after UpdatePanel asyncpostback

前端 未结 6 1321
时光取名叫无心
时光取名叫无心 2021-02-13 02:45

I have just noticed recently that my page title will reset to the standard \"Untitled Page\" after I perform an asyncpostback from inside my UpdatePanel in the main

6条回答
  •  我寻月下人不归
    2021-02-13 03:44

    It happens when you set the title progammatically and only when is not PostBack. Just rewrite save/load postback methods to hold the title in the viewstate bag.

        protected override void LoadViewState(object savedState)
        {
            object[] allStates = (object[])savedState;
            if (allStates[0] != null)
                base.LoadViewState(allStates[0]);
            if (allStates[1] != null)
                Page.Title = (string)allStates[1];
        }
    
        protected override object SaveViewState()
        {
            object[] allStates = new object[2];
            object baseState = base.SaveViewState();
            string pageTitle = Page.Title;
            allStates[0] = baseState;
            allStates[1] = pageTitle;
            return allStates;
        }
    

提交回复
热议问题