Unable to set value of the property ‘aSettings’

I developed a page, inheriting from LayoutsPageBase which was being displayed in a modal dialog using JavaScript similar to the following:

<script type="text/javascript">
    function DisplayCustomPopupPage() {
        var options = SP.UI.$create_DialogOptions();
 
        options.url = "http://urltocustompage/page.aspx";
        options.title = "Popup Page";
        options.allowMaximize = false;
        options.showClose = true;
        options.width = 800;
        options.height = 450;
 
        SP.UI.ModalDialog.showModalDialog(options);
    }

The DisplayCustomPopupPage function would be called from a click event on the page.

The popup page had an InputFormTextBox control on it that was configured for rich text mode.

The problem I encountered with this was a JavaScript error that said ‘null’ is null or not an object or Unable to set value of the property ‘aSettings’: object is null or undefined.

The line causing this error was in the RTE_ConvertTextAreaToRichEdit function defined in form.js

variables.aSettings=aSettings;

variables was null, so the problem seemed to be from the following call a few lines above.

var variables=RTE_GetEditorInstanceVariables(strBaseElementID);

Once the modal page loaded, the rich text control did not have the toolbar displayed or provide the expected functionality. If there was more than one InputFormTextBox control on the popup page, subsequent controls would display correctly. It appeared to me that the problem seemed to lie only with the first control. Also, I wasn’t seeing any error in Firefox or IE9, just IE8.

One solution I tried was to call the following script before the page rendered:

function EnsureRichEditControl(elementid, locale, siteUrl) {
  if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled()) {
      g_aToolBarButtons = null;
      if (g_fRTEFirstTimeGenerateCalled) {
          RTE_ConvertTextAreaToRichEdit(elementid, true, true, "", locale, null, null, null, null, null, "Compatible", siteUrl, null, null, null, null, false, 0, 0, false, true);
          RTE_TextAreaWindow_OnLoad(elementid);
      }
  }
  else {
      document.write("&nbsp;<br><SPAN class=ms-formdescription><a href='javascript:HelpWindowKey(\"nsrichtext\")'>Click for help about adding basic HTML formatting.</a></SPAN>&nbsp;<br>");
  }
}

This resulted in the problem control displaying correctly, but did not solve the JavaScript error that was being thrown prior to the model page displaying.

Turning off rich text mode for the control stopped the error from generating, but this was not a solution for me as I needed to be able to capture rich text. I should also mention that browsing to the page directly and not viewing it as a popup modal dialog did not generate a JavaScript error and everything worked as expected. So, for a reason I am unable to fully explain at this stage, the page being displayed as a modal dialog was causing the error. Although to further muddy the water, showing the page from the Edit Control Block (using similar JavaScript to show the dialog) did not throw an error…

The solution I settled on was to call the RTE_GetEditorInstanceVariables function, which was returning a null value the first time it was called – remember that subsequent controls calling this method were getting a valid result.

So, in the OnPreRender method of the modal page’s code behind, I implemented the following:

protected override void OnPreRender(EventArgs e)
{
    StringBuilder sb = new StringBuilder();
    sb.Append("<script language=\"javascript\">");
    sb.Append("try {");
    sb.Append(string.Format("    var dummyVariables = RTE_GetEditorInstanceVariables(\"{0}\");", inputFormTextBoxControl.ClientID));
    sb.Append("}");
    sb.Append("catch(e) {");
    sb.Append("    //suppress error");
    sb.Append("}");
    sb.Append("</script>");
 
    Page.ClientScript.RegisterClientScriptBlock(Page, GetType(), "dummyScript", script, false);
}

The variable dummyVariables will be assigned a null value (when run in an IE8 browser) but as it was not being used anywhere else it didn’t matter. What did matter was the fact that the next call to this method that previously caused a JavaScript error did not cause an exception to be raised, meaning the modal page showed without error and displayed the rich text control properly.

Hopefully this post will help someone else resolve this error and save them wasting unnecessary time and effort trying to solve it.

This entry was posted in JavaScript, SharePoint and tagged , . Bookmark the permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest

Solve the maths problem shown below before posting: *

2 Comments
Inline Feedbacks
View all comments
Felix

Thank you so much Stuart!
I had hassle with the same Problem and just thought about overriding the SharePoint JS functions when I found your post.