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

Forums / Developing with Sitefinity / Widget with HtmlField

Widget with HtmlField

7 posts, 1 answered
  1. Milan
    Milan avatar
    5 posts
    Registered:
    29 May 2009
    06 Nov 2013
    Link to this post
    Hi,

    I try to create widget with designer on Sitefinity 6.1. My widget contains two label controls. The widget designer contains one TextBox and one HtmlField. The TextBox in designer works fine. But I can't get value from widget and give it to the HtmlFiled indesigner. Also I can't get value from HtmlField and give it to the widget.
     I don't know what is wrong. ZIP with all files is here: www.develox.net/sitefinity/HtmlPanel.zip    
    Can anyone help me resolve this problem please?

    Thanks very much.

    Milan
    Answered
  2. Stephen2
    Stephen2 avatar
    94 posts
    Registered:
    05 Feb 2012
    09 Nov 2013 in reply to Milan
    Link to this post
    Here you go mate.  First line is current code, 2nd line is replacement code.  These complex control need to be passed with AddComponentProperty

    Designer.cs:
    ------------
    descriptor.AddElementProperty("htmlText", this.HtmlText.ClientID);
    descriptor.AddComponentProperty("htmlText", this.HtmlText.ClientID);

    Designer.js:
    ------------
    jQuery(this.get_htmlText()).val(controlData.HtmlText);
    this.get_htmlText().set_value(controlData.HtmlText);

    controlData.HtmlText = jQuery(this.get_htmlText()).val();
    controlData.HtmlText = this.get_htmlText().get_value();



    Remember to parse your HTML string before display, as it will now potentially have [sfref] images, links etc..:

    HtmlPanel.cs:
    -------------
    htmlTextLabel.Text = this.HtmlText;
    htmlTextLabel.Text = LinkParser.ResolveLinks(LinkParser.UnresolveLinks(this.HtmlText), DynamicLinksParser.GetContentUrl, null, false)
  3. Milan
    Milan avatar
    5 posts
    Registered:
    29 May 2009
    09 Nov 2013 in reply to Stephen2
    Link to this post
    Hi Stephen,

    thank you very much for your response. Your solution works fine. Could you please explain me where was the problem?
    I understand that I have to use the AddComponentProperty() for HTMLField. What about jQuery syntax? I see you are using direct access to the objects instead jQuery. Why?

    Another way: I used this together with AddElementProperty():
    -----------------------------------------------------------------
    this.get_htmlText().control.set_value(controlData.HtmlText);
    controlData.HtmlText = this.get_htmlText().control.get_value();

    And it works fine too.

    Thanks, Milan.

  4. Stephen2
    Stephen2 avatar
    94 posts
    Registered:
    05 Feb 2012
    09 Nov 2013 in reply to Milan
    Link to this post
    Glad I could help!  As to why ComponentProperty, or which way is better - I have no idea to be honest, I'm afraid I'm not experienced with any performance differences between the two methods.

    I always just "figure out what works" so if the ElementProperty way works too then I couldn't tell you which is better!  Good job figuring it out though.
  5. Milan
    Milan avatar
    5 posts
    Registered:
    29 May 2009
    11 Nov 2013 in reply to Stephen2
    Link to this post
    Stephen, thank you for help!
    For everyone, here is example, which works properly: www.develox.net/sitefinity/HtmlPanel.zip

    Good luck!
  6. John
    John avatar
    1 posts
    Registered:
    10 Dec 2012
    02 Dec 2013 in reply to Milan
    Link to this post
    Hi Milan,

    I'm having the same issue.  The link to your solution file is no longer working.  Would it be possible for you to attach your solution to your response?

    Thank you.
  7. Milan
    Milan avatar
    5 posts
    Registered:
    29 May 2009
    03 Dec 2013 in reply to John
    Link to this post
    Hi John,

    the link is corrected. I am sorry. Try it again.
    Thank you for your notice.
7 posts, 1 answered