Using SP.UI.Dialog and SP.UI.Notify from code behind

SharePoint 2010 comes with the SP.UI framework. This is a JavaScript library which you can use to interact with the SharePoint UI. I wanted to use the SP.UI framework to display a dialog which is only shown when condition are met in code behind.

ValidationDialogWebPart

When I placed the JavaScript in the web part I got a null reference error. The problem originated from the SP.UI object model not being loaded. Especially because it did work when I executed the script on the OnClick event of a button.

The solution is provided by the SP.SOD.executeOrDelayUntilScriptLoaded method. It will wait to execute the function you provide until the script you refer is completely loaded.

ExecuteOrDelayUntilScriptLoaded(ShowDialog, "sp.js");

Within my project I added a JavaScript file containing my method “ShowDialog()” to show the dialog. Within my web part I perform the validation and call the CreateDialog() method.

/// <summary> /// Registers the javascript supporting showing dialog. /// </summary> /// <remarks> /// When calling this method, the dialog is shown /// to the user and blocks the page below. /// </remarks> private void CreateDialog() { // Define the name and type of the client scripts on the page. string csname = "ShowDialogScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, csname)) { StringBuilder js = new StringBuilder(); js.Append("<script type='text/javascript'>"); js.Append("ExecuteOrDelayUntilScriptLoaded(ShowDialog, 'sp.js');"); js.Append("</script>"); cs.RegisterStartupScript(cstype, csname, js.ToString()); } }

Access Denied errors in content source for People Search

Having issues with indexing the user profiles? Getting Access Denied error messages in the crawl log for sps3://my.sharepoint.com? Are these looking like the one below?

Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled. ( HttpStatusCode Unauthorized The request failed with HTTP status 401: Unauthorized. )

This most likely has to do with the default content access account not having access to the user profile service application. The default content access account needs “Retrieve People Data for Search Crawlers” permissions on the user profile service application.

Search error message Access Denied

Solving this is rather easy. See steps below:

  1. Navigate to the Central Administration
  2. Click on Manage Service Applications
  3. Select the “User Profile Service Application” (note: do not click the name of the service application, because you will be redirected to management page)
  4. Click in the ribbon on the Administrators button
  5. Add the “Default content access account” to the accounts list
  6. Select the “Default content access account” in the list
  7. Check the “Retrieve People Data for Search Crawlers” permission
  8. Click OK

Administrators dialog for User Profile Service Application