Sharepoint, ajax and page title

一个人想着一个人 提交于 2019-12-06 08:03:32

问题


I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed inside webpart. When partial postback occurs, page title gets missing.

We have found that temporary partial solution is to write title element into one line and not use any spaces or controls inside it..not even a literal control.

But we need some way to provide sommon title for all pages, so title would look like this: My default title - Current page title

Any ideas how to solve this?


回答1:


I don't have a reference to the newsgroup post, but this is a known problem with publishing pages, as drax mentioned. The workaround I have used in the past is to hard code the title on the page - the metadata title being lost is part of the bug.

When hardcoding wasn't possible, I have used javascript to change the page title: document.title = "title fixup here";

Supposedly microsoft plans to fix this problem in the next sharepoint release.




回答2:


I thought I would share my solution to this pesky issue. What I ended up doing was throwing down this handy little script I put put together below. You can put this in your custom page layout or custom master page. It works by wiring up an AJAX event handler to grab the title before AJAX changes it and then re-applies it using Darpy's code above. This allows for the proper page title to always show.

<script type="text/javascript">

// This script is to fix the issue where AJAX causes SharePoint 
// publishing pages to sometimes make the page title something 
// whacky. 
var app = Sys.Application;
var origTitle = "";
app.add_init(SPCustomAppnInit);


function SPCustomAppnInit(sender) {
  origTitle = document.title; // grab the original title.
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  if (!prm.get_isInAsyncPostBack())
  {
 prm.add_pageLoaded(SPCustomPageLoaded); // wire up loaded handler.
  }
}

function SPCustomPageLoaded(sender, args) {

 document.title = origTitle; // put the original title back on the document.
}

<script>



回答3:


I realize that this has been answered already, but I'm going to throw in my $.02. It appears that the problem manifests itself because of two conditions: (1) using an AJAX asynchronous postback and (2) having a multi-line <title> element in the <head> of the page.

Check your master page. If it has something along the lines of this:

<title>
<sharepointwebcontrols:listitemproperty property="Title" ...>
</title>

...then change it to be all on one line, like so:

<title><sharepointwebcontrols:listitemproperty property="Title" ...></title>

Problem solved. No javascript required.




回答4:


this looks like pure sharepoint's problem..also it looks like just sites based on publishing page layout are affected.

I debugged response in firebug and for some reason it returns setting for page title, so response from server contains not just update panel information, but also empty page title.

I debugged our webparts and none of them plays with page title. I would suggest not to use publishing or just not use any controls inside title.

We are currently working on this issue in company i work for, so i'll upload uour findings when we figure out something.




回答5:


Adding the following @ the begining of my webpart user control Fixed the issue

<script type="text/javascript"> 

// This script is to fix the issue where AJAX causes SharePoint  
// publishing pages to sometimes make the page title something  
// whacky.  
var app = Sys.Application; 
var origTitle = ""; 
app.add_init(SPCustomAppnInit); 


function SPCustomAppnInit(sender) { 
  origTitle = document.title; // grab the original title. 
  var prm = Sys.WebForms.PageRequestManager.getInstance(); 
  if (!prm.get_isInAsyncPostBack()) 
  { 
 prm.add_pageLoaded(SPCustomPageLoaded); // wire up loaded handler. 
  } 
} 

function SPCustomPageLoaded(sender, args) { 

 document.title = origTitle; // put the original title back on the document. 
} 

</script> 

thanks ALOT :D



来源:https://stackoverflow.com/questions/325461/sharepoint-ajax-and-page-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!