pvitt
pvitt

Reputation: 1065

registry.byID set content returns Unable to get property 'set' of undefined or null reference

Trying to set the content of content pane with registry.byId, but I'm not able to get the object -- I get the following error:

JavaScript runtime error: Unable to get property 'set' of undefined or null reference

my code is like this:

 require(["dojo/parser", "dojo/dom", "dijit/registry", 
"dojox/layout/ContentPane", "dojo/domReady!"],
 function (parser, dom, registry) {

parser.parse();

registry.byId("Content").set("content", "Test Content");//Content ID is not being found

 });

</script>
<div data-dojo-type="dijit/layout/BorderContainer" id="Main" style="width: 100%; height: 100%">
 <div data-dojo-type="dojox/layout/ContentPane" id="TOC" data-dojo-props="splitter: true, region:'leading'">
 TOC
 </div>
 <div data-dojo-type="dojox/layout/ContentPane" id="Content" data-dojo-props="splitter: true, region:'center'">
 </div> 

Any ideas? Thanks!

Upvotes: 1

Views: 1126

Answers (2)

BuffaloBuffalo
BuffaloBuffalo

Reputation: 7852

It's worth noting that since dojo 1.8, the parser.parse() call returns an array with a Promise mixed in, so the recommended way of interacting with parsed objects is

parser.parse().then(function(){
    registry.byId('content'.set('content','test content');
});

Using dojo/ready should achieve the same effect though.

Upvotes: 0

frank
frank

Reputation: 3330

I think the widgets are in the process of being created and they are not ready yet when you call the registry.byId() call.

you need to add the initialization code in the ready() call by including the "dojo/ready" module.

require(["dojo/parser", "dojo/dom", "dijit/registry", "dojo/ready",
          "dojox/layout/ContentPane"],
function (parser, dom, registry, ready) {

   parser.parse();
   ready( function(){

      // your code goes here.
      registry.byId("Content").set("content", "Test Content");

   });
}

});

Upvotes: 1

Related Questions