April 30, 2012

Using HttpContext.GetGlobalResourceObject in webpart development

We found interesting issue during working with global resource files this week.

Event if we are using HttpContext.GetGlobalResourceObject, web part was rendering data in English even if site language is other than English!

If we switch to edit mode, it was working sometime, but most of the time it was showing English text.

Root cause:
We tried creating a new application page and placed a webpart there, it was strange that it was working properly in the application page.

We finally found that at the time of reading resources through  HttpContext.GetGlobalResourceObject web part was not aware of the current UICulture


   1:  var strLinkText = HttpContext.GetGlobalResourceObject("file", "key");

   1:  var strLinkText = HttpContext.GetGlobalResourceObject("file", "key",SPContext.Current.Web.UICulture);

Finally after passing third argument from SPContext.Current.Web.UICulture it worked properly
If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment