Type.createInstance

Last post 07-24-2006 10:17 AM by Hooper. 8 replies.

Sort Posts:

  • Type.createInstance

    07-20-2006, 9:41 AM
    • Member
      40 point Member
    • Hooper
    • Member since 06-28-2006, 5:34 AM
    • Posts 8

    Hi All

    I copied new version on Atlas of june, and get next problem.

    I try registred type: e.g.

    pageClassName - is string;
    var _page = Type.createInstance(pageClassName); // create an instance of JavaScript class

    but i get error.

    When i execute method Type.createInstance, i get method

    Function.createInstance = function(type) {
       if (typeof(type) != 'function') {
          type = Function.parse(type);
       }
    return new type();
    }

    and type says null; Is bug Atlas (CTP JUNE).

    Why class Function, I don't understand.

    version v2.0.50727

    date Microsoft.Web.Atlas.dll - 06/27/2006

    Please I need Help.

     

     

  • Re: Type.createInstance

    07-20-2006, 5:36 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    hello.

    can you post a sample that reproduces this?

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Type.createInstance

    07-21-2006, 4:07 AM
    • Member
      40 point Member
    • Hooper
    • Member since 06-28-2006, 5:34 AM
    • Posts 8

    So,

    In the master page i have next code:

    <atlas:ScriptManager ID="ScriptManager2" runat="server">
       <Scripts>
          <atlas:ScriptReference path="HeatService.asmx/js" />
          <atlas:ScriptReference path="js/core.js" />
       </Scripts>
       <Services>
          <atlas:ServiceReference Path="HeatService.asmx" />
       </Services>
    </atlas:ScriptManager>

    I have the file  core.js this class load class mainpage

    I registred it.

    FRS.Web.MainPage.registerClass(

    'FRS.Web.MainPage', FRS.Web.MDIFrame);

    I do the followoing:

    1) . I try to load js MainPage.js

    var scriptLoader = new Sys.ScriptLoader();
    references.queue(url);
    scriptLoader.load(references, Function.createDelegate(
    this, onPageLoaded), jsScriptContext);

    2).  Hereon must execute next string

    FRS.Web.MainPage.registerClass('FRS.Web.MainPage', FRS.Web.MDIFrame);

    3). than
    here error
    _page = Type.createInstance(pageClassName); // create an instance of JavaScript class
    because  class is not loaded. In APRIL CTP all ok. 

    _page.onInit(_parentPage, pageClassArguments); //initialize it

    Is it bug Atlas?

     

     

  • Re: Type.createInstance

    07-21-2006, 5:16 AM
    • Member
      40 point Member
    • Hooper
    • Member since 06-28-2006, 5:34 AM
    • Posts 8

    Here sample. Please say me bug or not bug Atlas

    file Dedault.aspx

    <%

    @ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head runat="server">
       <title>Untitled Page</title>
       <atlas:ScriptManager ID="ScriptManager1" runat="server" >
          <Scripts>
             <atlas:ScriptReference path="js/page.js" />
          </Scripts>
       </atlas:ScriptManager>
    </
    head>
    <
    body>

       <form id="form1" runat="server">
          <div>
             <input type="button" onclick="Initialize();" value="test"/>
          </div>
        </form>
    </
    body>
    </
    html>

    file page.js

    Type.registerNamespace(

    "Test");

    Test.Page =

    function () {

    /* @Desc: Callback method to be called on a successful page download

    * @param: context is a composite parameter that contains

    * URL - of a page has been successfully downloaded.

    * pageClassName - class name of a Javascript class that contains the unit of application logic downloaded

    * pageClassArgument - collection of argument to be passed to the class above

    */

    function onPageLoaded(context) {

    var url = context.url;

    var pageClassName = context.pageClassName;

    var pageClassArguments = context.pageClassArgument;

    return _process(url, pageClassName, pageClassArguments);

    };

    /* @Desc: Instantiate a JavaScript class and call methods on a page for it to download forms and data relevant to the downloaded unit

    * @param: URL - of a page has been successfully downloaded.

    * @param: pageClassName - class name of a Javascript class that contains the unit of application logic downloaded

    * @param: pageClassArgument - collection of argument to be passed to the class above

    */

    function _process(url, pageClassName, pageClassArguments) {

    _page = Type.createInstance(pageClassName);

    // create an instance of JavaScript class

    _page.onInit(_parentPage, pageClassArguments);

    //initialize it

    };

    this.load = function(parent, url, pageClassName) {

    var references = [];

    _parentPage = parent;

    var pageCallArguments = new Array();

    for (var i=3; i<arguments.length; i++)

    pageCallArguments[i-3] = arguments[i];

    /* var ref = new Object();

    ref.url = url;

    ref.onscriptload = Function.createDelegate(this, onPageLoaded);*/

    var jsScriptContext =

    {

    url: url,

    pageClassName: pageClassName,

    pageClassArgument: pageCallArguments

    };

    var scriptLoader = new Sys.ScriptLoader();

    references.queue(url);

    scriptLoader.load(references, Function.createDelegate(

    this, onPageLoaded), jsScriptContext);

    };

    };

    Test.Page.registerAbstractClass(

    'Test.Page', null, Sys.IDisposable);

    function

    Initialize() {

    debugger;

    var controller = new Test.Page();

    controller.load(

    null, "js/main.js","Test.Main");

    };

    and file main.js 

    Test.Main =

    function () {

    };

    Test.Main.registerClass(

    'Test.Main', Test.Page);
     Thats all. When we execute method Type.createInstance we get error.
  • Re: Type.createInstance

    07-24-2006, 6:38 AM
    • Member
      40 point Member
    • Hooper
    • Member since 06-28-2006, 5:34 AM
    • Posts 8

    Luis Abreu

    Do you know, what is it? Help please.

  • Re: Type.createInstance

    07-24-2006, 6:56 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    hello.

    well, believe me: i do want to help. in order to do that, i must understand what you're doing nad that is what i'm asking. if you look at the _process method you've defined, you'll see that it has a class_page var which is being used. this class_page is undefined. what's the purpose of this variable?

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Type.createInstance

    07-24-2006, 9:54 AM
    • Member
      40 point Member
    • Hooper
    • Member since 06-28-2006, 5:34 AM
    • Posts 8

    var

    _page; // reference to the page that is downloaded
  • Re: Type.createInstance

    07-24-2006, 10:09 AM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    hello again.

    ah, got it.

    now thati'm able to run your code, i must ask one more thing: where's the onInit method? it's not defined on the Test.Page class nor in the Test.main class...

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Type.createInstance

    07-24-2006, 10:17 AM
    • Member
      40 point Member
    • Hooper
    • Member since 06-28-2006, 5:34 AM
    • Posts 8

    Sorry, I fogotted add this method.

    Here you are

    this.onInit = function(parentPage, pageClassArguments) {

    };

Page 1 of 1 (9 items)