开发者

ScriptManager globalization issue

I'm having a problem with the asp:ScriptManager not working correctly under SharePoint. I have set EnableScriptGlobalization="true" to be able to use the Sys.CultureInfo object of ASP.NET AJAX, but because of the script is being output in the wrong order, it's not working. The same code works correctly under a plain ASP.NET site, so the issue seems related to SharePoint somehow. Though it did work correctly under SharePoint 2007.

To reproduce the issue, I created this simple usercontrol CultureControl.ascx.

<%@ Control Language="C#" %>
Server side culture: <%= System.Threading.Thread.CurrentThread.CurrentCulture.Name %><br />
Client side culture: <script type="text/javascript">document.write(Sys.CultureInfo.CurrentCulture.name);</script><br />

When I include this control on a regular ASP.NET web site .aspx page, and set the culture to sv-SE on the server side, the output is as expected.

Server side culture: sv-SE

Client side culture: sv-SE

But when I put the same usercontrol on a page in a SharePoint 2010 site, set the site locale to Swedish and set EnableScriptGlobalization="true" in the master page, I still get the output

Server side culture: sv-SE

Client side culture: en-US

When I started digging in to this problem, I noticed that the reason was that the script blocks that the ScriptManager outputs are in the wrong order. When EnableScriptGlobalization is set to true, the Scrip开发者_如何转开发tManager outputs a script block that defines a __cultureInfo variable, which is then used to initialize the Sys.CultureInfo. This variable has to be defined before MicrosoftAjax.js is loaded, otherwise it will default to en-US culture.

In the ASP.NET site, this works correctly. The __cultureInfo variable is defined first, then MicrosoftAjax.js is loaded from WebResource.axd. But under SharePoint, MicrosoftAjax.js is loaded a lot earlier and the __cultureInfo variable is defined too late.

Does anyone know of a solution or workaround for this issue?


One solution i am doing and its working perfectly. Add the following at the end of your page (Master Page)

<script>
if (__cultureInfo)
{
   Sys.CultureInfo.CurrentCulture = Sys.CultureInfo._parse(__cultureInfo);
   delete __cultureInfo;
}
</script>

UPDATE: I wrote a wrong solution before, now the above one is properly updated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜