custom widget wiring issue

Posted by Community Admin on 04-Aug-2018 21:06

custom widget wiring issue

All Replies

Posted by Community Admin on 21-Feb-2014 00:00

I'm very new to Sitefinity so I am sure this will be a easy one (not for me).

I used Thunder to create the default "Hello World" custom widget and designer ... just so I could play with it.   I called it "HelloWorldTest"

The strange thing is, when I look at the code that is generated I see a basic  HelloWorldTest.ascx but without any code behind.    

<%@ Control Language="C#" %>
<asp:Label ID="MessageLabel" Text="Text" runat="server"/>

There is also the designer and a HellowWorldTest.cs file, but I see no way in which these files are linked. 

As expected, when I registered this widget in tools and placed it on a page it just displays "Text", and when it click "Edit" it gives me the standard designer without the "Message" property.

Am I supposed to add some code behind to the ASCX file to bootstrap the registering of the custom property and designer?

I have a feeling I am missing the obvious here, but have been struggling for a while.

Any hints would be greatly appreciated.

Posted by Community Admin on 22-Feb-2014 00:00

Okay so they are linked :). In the .cs there should be a string that points to the ascx...at the bottom I think.  Anyway, the ascx is more like a 'view' so the code file can't directly access the controls on it AUTOMATICALLY.; you just need to wire them up.  So in the sample see how in the control references region  it finds the message label in the container?...thats all you need then you can access as you always would.

The other diff is you can't wire an event in the markup.  You need to hook it in through code in the InitalizeControls method.

Posted by Community Admin on 22-Feb-2014 00:00

Sorry...2 separate posts because I'm on an ipad and the mobile styling on this forum is so badly gimped.
So the designer class is wired up through an attribute on the main SimpleView inherited class.  I find its best to make the control without a designer.  Then when I have all my properties added, fire up thunder again and 'add designer for existing widget'.

Posted by Community Admin on 22-Feb-2014 00:00

Thanks for throwing me a lifeline there Steve.  I actually understood most of that already but began to doubt myself when nothing seemed to work.   At least I know I have not just spontaneously lost my mine.

Never-the-less, I still can't get this silly thing to work.   I deleted the old widget and started again from scratch ... this time the widget is called "ProductTest"

As you indicated, the CS file is wired up to the ASCX file at the end using:

        #region Private members & constants
        public static readonly string layoutTemplatePath = "~/Widgets/ProductTest/ProductTest.ascx";
        #endregion

I then hardcoded some text into the "initializecontrols" method to know for sure which path the execution was taking
        protected override void InitializeControls(GenericContainer container)
       
            Label messageLabel = this.MessageLabel;
            if (string.IsNullOrEmpty(this.Message))
           
                messageLabel.Text = "Hello, World!";
           
            else
           
//                messageLabel.Text = this.Message;
                messageLabel.Text = "testing testing 123";
           
       
The ASCX file has the text "Test me" so that I will know if it is simply displaying the 'view' (as you correctly descried it)
<%@ Control Language="C#" %>
<asp:Label ID="MessageLabel" Text="test me" runat="server"/>

The class grabs a reference to the control like so:

        protected virtual Label MessageLabel
       
            get
           
                return this.Container.GetControl<Label>("MessageLabel", true);
           
       

Finally, the designer is be hooked in at the top of the CS file like so:

[Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesigner(typeof(SitefinityWebApp.Widgets.ProductTest.Designer.ProductTestDesigner))]

The widget itself is registered 
with the "Control CLR Type or Virtual Path" set to:

  ~/Widgets/ProductTest/ProductTest.ascx

When I preview the page all I ever see is "test me", the text that is found in the ASCX.    

It as if the class never gets looked at ! ... This is substantiated by  fact that I just get a default designer when I click "edit" on the widget when it is placed within the page.

Maybe I am not registering it correctly?   I tried selecting the "Register" option when creating the widget in thunder and that was an epic fail ... when tried to add the widget to a page it would always throw an error saying that Type 'xxxx' couldn't be resolved.   So I ended up doing it the way I had seen in other videos and specifying the URL path.

Anyway ... getting a little frustrated, but I am sure the solution will be simple (once I find it).

Any further thoughts?

 

Posted by Community Admin on 22-Feb-2014 00:00

Heres a quick video of what I do...

screencast.com/.../ppsBn9Be1VC

Posted by Community Admin on 24-Feb-2014 00:00

Good news!   FINALLY got it working!! ... but not the way you might think.

I initially followed your video to the pixel and AGAIN nothing worked ... Even when I hardcoded some text into the initialize method it still didn't render the message.

I then ran around the yard screaming a few times and that made me feel much better ;) 

Decided to start a brand new project from scratch and try it again.... created a new project / database etc .... created a new custom widget from scratch using your video and it worked like a charm right from the start.

Somehow, someway, I managed to break my old project and didn't realize it, so nothing I build within that project seemed to work ... no errors .. just nothing ... feel a bit silly because I should have guessed something was up when the very basic vanilla generated code from Thunder didn't work.

Anyway ... all's well that ends well ... I learned a few things along the way and only lost a few hairs in the process.

Thanks for sticking with me while I went through this.

-Sheldon

This thread is closed