Page losing title after UpdatePanel asyncpostback

前端 未结 6 1304
时光取名叫无心
时光取名叫无心 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:25

    We ran into this exact issue on one of our sites.

    The immediate fix was to reset the title in the master page codebehind page_load method.

    Apparently when the ajax call occurs, it is rerunning the master page. This was causing our title to disappear.

    For example:

    protected void Page_Load(object sender, EventArgs e) {
        this.Page.Title = "whatever title you have...";
    }
    

    A better fix is to drop the MS updatepanel crap and start using JSON / jQuery where you actually have some decent control over the calls.

    0 讨论(0)
  • 2021-02-13 03:30

    Are you opposed to using the Title property of the Content Page?

    <%@ Page Title="Your Page Title" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/...
    

    You can also access this programmatically in the page load...

    0 讨论(0)
  • 2021-02-13 03:35

    Is a weird bug that can be workedaround if you remove the spaces in the title tag like:

    <title><asp:ContentPlaceHolder id="title" runat="server"></asp:ContentPlaceHolder></title>
    

    Tested on Sharepoint 2010

    0 讨论(0)
  • 2021-02-13 03:36

    Rather than change your server side code, why not just fix it in JS:

    $(function(){
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        if (!(prm)) return;
        document.orginalTitle=document.title;
        prm.add_endRequest(function(s, e){
            if (document.title.replace(/\s/g,"").length==0)
                document.title=document.orginalTitle;
            });
    });
    
    0 讨论(0)
  • 2021-02-13 03:40

    You could put the Page title in Viewstate and then just grab the string in the button postback Click event and assign it to Page.Title

        public string MyPageTitle
        {
            get
            {
                return (string)ViewState["MyPageTitle"];
            }
            set
            {
                ViewState["MyPageTitle"] = value;
            }
        }
    

    On Page load assign: MyPageTitle = "My Cool Web Page Title"; Then in button click event:

    protected void MyLinkButton_Click(object sender, EventArgs e)
        {
    
           Page.Title = MyPageTitle;
    
        }
    
    0 讨论(0)
  • 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;
        }
    
    0 讨论(0)
提交回复
热议问题