+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Undefined or null reference error when clicking 'edit' on a custom widget

Undefined or null reference error when clicking 'edit' on a custom widget

8 posts, 0 answered
  1. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    29 Sep 2012
    Link to this post
    Built a custom user control. When I click 'Edit' I get an error from Microsoft AJAX:

    Unable to get property 'FancyBlockDesigner' of undefined or null reference

    Sys.Application.add_init(function() {
        $create(SitefinityWebApp.Esd.TheLab.SampleHtmlEditor.FancyBlockDesigner, null, null, {"propertyEditor":"propertyEditor"}, $get("propertyEditor_ctl00_ctl00_ctl00"));
    });


    Any idea how to troubleshoot or fix this? Being that it is a mix of C# and JS, I cannot step through the code, so it is hard to know what part of my User Control would be causing the issue. Ideas?

    (if I can bribe you with StackOverflow credit, you can reply to the same issue over there)

    (Kind of hard to keep this question short and sweet, so if this sounds like something you've run into, I'll be happy to add more detail as needed)
  2. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    29 Sep 2012
    Link to this post
    On another widget, I got the following output that DID work. It looks similar, so maybe the JavaScript is correct.

    Sys.Application.add_init(function() {
        $create(SitefinityWebApp.Esd.Common.QuoteBlock.quoteboxDesigner, null, null, {"propertyEditor":"propertyEditor"}, $get("propertyEditor_ctl00_ctl00_ctl00"));
    });

  3. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    29 Sep 2012
    Link to this post
    Aha! I found another thread on the same topic. See this here:
    http://www.sitefinity.com/devnet/forums/sitefinity/developing-with-sitefinity/problem-creating-designer-for-custom-widget.aspx 

    Some of these JavaScript errors are so generic, they are hard to research.
  4. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    29 Sep 2012
    Link to this post
    Still hasn't helped yet. Hmm... Custom designers are tough, so much code that can go wrong. I'm finding that most of it is related to the Microsoft AJAX library, and not Sitefinity's code base specifically.

    I've been hearing 'use Thunder', but what if I'm working on a pre-thunder Custom User Control?
  5. MB
    MB avatar
    302 posts
    Registered:
    09 Jan 2005
    29 Sep 2012
    Link to this post
    @Dan

    $create(type, properties, events, references, element) is the in-line jscript that instantiates your designer script. It is created from the list/array of ScriptDescriptors returned from GetScriptDescriptors()

    By default, if you are deriving from ControlDesignerBase, then you use base.GetScriptDescriptors() as the starting point for building the designers descriptors, and add any specific properties and/or references, such as designer-specific UI controls.

    The base descriptor provides the reference to the propertyEditor, which is the access to all your control's public properties. You override the base.GetScriptDescriptor() to add your own.

    Basically, your designer needs to do something like:
    public override IEnumerable<System.Web.UI.ScriptDescriptor> GetScriptDescriptors()
            {
                //-- Load the Descriptors from ControlDesignerBase
                var descriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
     
                //-- Get the last one and box it as a ScriptControlDescriptor (this type of descriptor is assumed)
                var descriptor = (ScriptControlDescriptor) descriptors.Last();
                 
                //-- Add any extra Property Descriptors - e.g. Passing a unique value for the script to use
                //   requires the client script to contain a get/set_client_property_name
                descriptor.AddProperty('client_property_name', property_value);
     
                //-- Add any extra Reference Descriptors - e.g. Passing a ref to a RadNumericTextBox
                //   requires the client script to contain a get/set_client_property_name
                descriptor.AddComponentProperty('client_property_name', 'control_client_id');
     
                //-- Return the descriptors so asp.net can build/render the required $create()
                return descriptors;
            }

    Hope that helps.
  6. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    29 Sep 2012
    Link to this post

    That explanation helps a lot. Thank you! I will try it out Monday and let you know.

    The line between the Telerik and Microsoft technologies is the trickiest to figure out as the documentation is in two places.
    Your tip about viewing the source of the widget editor window earlier today was useful as well.

  7. Marin Atanasov
    Marin Atanasov avatar
    62 posts
    Registered:
    24 Sep 2012
    01 Oct 2012
    Link to this post
    Hello Dan,

    I apologize but I am going to be the next person that will tell you to 'use Thunder'. It can generate a working designer for some of your control's public properties.

    Thunder can create a designer for an already existing user or custom control in C# or VB. All you need to do is remove the ControlDesigner attribute if your control has one and build your project, select where you wish to put the designer files (they have to be in the same project as the control itself), open the context menu, select Add -> New Item..., select "Designer for Existing Widget", enter the name of the designer and click Add. A wizard will appear and take you through the rest of the steps to create the designer. For more information, please check the documentation about Creating widget designers with Thunder. There is a section that explains how to Create a designer for an existing widget.

    For more information about Sitefinity Thunder and how to install it, please visit our Sitefinity Thunder documentation.

    For more information about the designer files and how to create/edit them manually, please visit the documentation about Creating simple control designers.

    Please let me know if you need further help creating your widget designer.

    All the best,
    Marin Atanasov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. MB
    MB avatar
    302 posts
    Registered:
    09 Jan 2005
    01 Oct 2012
    Link to this post

    Thunder is a really useful tool, and is very good for creating basic designers for standard control implementations.

    I agree - if I were new to Sitefinity and/or designers, there would be absolutely no contest in where to start creating a designer for a widget - Thunder.

    It basically appears to work by reading the public/browsable properties of the control (i.e. those listed in the property editor) and then generating a boiler-plate designer with lots of // Your code goes here //  type of lines - and it does a good job of that.

    However, things get less certain the more advanced/specialized your environment and/or the more experience/knowledge you have with the base technology... and like all code-generating tools, Thunder has its limitations.

    The biggest issue with 'doing your own thing' and manually creating designers is the assumption that you are fully conversant in asp.ajax as the primary client platform.

    Prior to Thunder, this assumption made developing even the simplest of designers, a serious challenge for people without that background, as the learning curve was near vertical, and Telerik (quite rightly) didn't attempt to teach developers that base technology.

    This made going from V3 to V4/5 quite difficult for the average dev with little prior need of in-depth asp.ajax experience, as half of the required information is missing - and getting to grips with it was made all the harder by Microsoft's decision on the future of asp.ajax.

    Personally, starting with V4 came as a shock to find how much I needed to learn, and it was nearly 2 years of pain - partly because I'm so stupid, but partly because the documentation was so sketchy on both Telerik's and Microsoft's sides.

    I have custom environment at both server and client levels that Thunder really struggles to deal with, let alone enhance, but that's not unreasonable and I'm accept my trade-off as a choice of development priorities.

    However, having got to the point where I no longer feel I'm just a passenger in the development cycle, I'm not about to give it up... LOL.

8 posts, 0 answered