Tuesday, February 19, 2013

Retrieving a resource key in a custom LayoutsPageBase page used in SP2010

1. Create the following property in your aspx.cs file:

protected Type ResourceType
          return typeof(MyResources); // replace 'MyResources' with your own resources file

2. Create the following method which will return the requested value stored in the .resx file by looking up the resource key

protected string GetResourceString(Type resourceType, string resourceKey)
     return SPUtility.GetLocalizedString(string.Format("$Resources:{0}, {1}", resourceType.Name, resourceKey), resourceType.FullName, getLanguage);

3. Good to go. Say you would need to populate a label in the Page_Load event with a string stored in the resources file with a key called 'MyLabelText'; you can then achieve this as follows:

protected void Page_Load(object sender, EventArgs e)
     lblMyLabel.Text = GetSourceString(ResourceType, "MyLabelText");

Thursday, February 14, 2013

How to refresh parent page after closing a SP.UI.ModalDialog

var options = {
 title: 'Your Application Page Title',
 allowMaximize: false,
 showClose: true,
 width: 700,
 height: 260,
 dialogReturnValueCallback: RefreshOnDialogClose

Key here is the callback function; set it to RefreshOnDialogClose. Dead simple ;-)