Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • René Pjengaard 117 posts 700 karma points c-trib
    Jan 11, 2010 @ 21:22
    René Pjengaard
    0

    Saving tags in custom user control

    Hi there,

    i´m a bit stuck in my solution. I´m trying to use umbraco´s editorControls to put tagging in my custom control. The control is used for creating a document with tags. I have found out, how to use umbraco.editorControls.tags.DataType to get the tag-editor in to the control.

    //tags
    var tagKashmir = new umbraco.editorControls.tags.DataType();
    phTagKashmir.Controls.Add(tagKashmir.DataEditor.Editor);

    But i just can´t figure out, how to save the tags in my document. All other properties are saved like this:

    var dt = DocumentType.GetByAlias("KashmirZoom");
    var author = User.GetUser(AuthorId);
    var titel = TitelKashmir.Text.Trim();
    var content = ContentKashmir.Text.Trim();
    DateTime eventdate;
    DateTime.TryParseExact(((TextBox) phEventDateKashmir.Controls[0]).Text, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out eventdate);
    
    var doc = Document.MakeNew(titel, dt, author, 1099);
    doc.getProperty("content").Value = content;
    doc.getProperty("eventdate").Value = eventdate;
    //doc.getProperty("kashmirTags").Value = tags;
    
    doc.Publish(author);
    library.UpdateDocumentCache(doc.Id);
    

    I am getting nuts over this one.

     

    Best regards
    René

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Jan 11, 2010 @ 21:36
    Richard Soeteman
    0

    Hi Ithink you should take a look at the source code of Blog4Umbraco. That is using an Usecontrol to create posts with tags also. You'll find it here

    Cheers,

    Richard

  • René Pjengaard 117 posts 700 karma points c-trib
    Jan 12, 2010 @ 12:32
    René Pjengaard
    0

    Hi Richard

    i did look in Blog4Umbraco yesterday, and didn´t find anything usable. In the folder "usercontrols" there is only a file for AjaxCommentForm.ascx and BlogInstaller.ascx. I found a control under "Dashboard" called CreatePost.ascx, but i see no tag-saving. Do you know exactly where to look?

    Regards
    René

  • Thijs 97 posts 117 karma points
    Oct 14, 2011 @ 09:40
    Thijs
    0

    Hi, I'm having the same problem. did you remember how you solved the issue?

  • Richard 146 posts 168 karma points
    Oct 14, 2011 @ 10:27
    Richard
    0

    Hi Thijs,

    I did this recently, I created a new DataType tag, so that I could give a unique tag group, clients in my case. This is so that you can keep your tags separate:

    In the user control do what Rene was doing, up to and including the doc.publish. You now have the ID of the new documents (doc.Id).

    Then check to see if the tag has been used before:

    XPathNodeIterator tags = umbraco.editorControls.tags.library.getAllTagsInGroup(_tagGroup);                
    XPathNodeIterator nodes = tags.Current.Select("tags/tag");

    if (nodes.Count > 0)
    {
    newTagValue = newTagValue.Trim().ToLower();

    foreach (XPathNavigator node in nodes)
    {
    if (node.Value.ToLower() == newTagValue)
    {
    return true;
    }
    }
    }
    return false;

    If it is a new tag, you need to save the tag value entered into the DB table that contains the tags,

    umbraco.editorControls.tags.library.AddTag(newTagValue, _tagGroup);

    Where _tagGroup is "clients" in my example. You then need to save to DB that your new document is using the tag:

    umbraco.editorControls.tags.library.addTagsToNode(doc.Id, newTagValue, _tagGroup);

    The update the cache:

    umbraco.library.UpdateDocumentCache(doc.Id);

    The only comment, is that I was only receiving one tag value, where it may be possible to save multple comma separated tags in one go.

    Richard

  • Thijs 97 posts 117 karma points
    Oct 14, 2011 @ 11:02
    Thijs
    0

    wow that's some pretty awesome code! When I try to add my tags to my usercontrol I get the exception that I need a scriptmanager.. When I add a scriptmanager I get the error that my tags aren't set to an object reference.. Any ideas how to solve this? private umbraco.editorControls.tags.DataType tags;

    //ScriptManager script = new ScriptManager(); 
    //this.Controls.Add(script);

    tags = new umbraco.editorControls.tags.DataType();
    this.Controls.Add(tags.DataEditor.Editor);

  • Richard 146 posts 168 karma points
    Oct 14, 2011 @ 11:22
    Richard
    0

    To fix the script manager error, you need to add ScriptManager tag to the MasterTemplate:

    <body>
    <form id="siteForm" runat="server">
    <asp:ScriptManager ID="scriptMgr" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>

    I just used a text box for the user to enter the tags, and drop down control to display tags that already existed, as that best suited our requirements. What are you trying to achieve with your code?

    Richard

  • Thijs 97 posts 117 karma points
    Oct 14, 2011 @ 11:28
    Thijs
    0

    I'm trying to make a usercontrol so you don't have to login to the backend to make blogposts using the Blog4Umbraco package. I'm trying your code right now.

    I really appreciate your help!

     

    Thijs

Please Sign in or register to post replies

Write your reply to:

Draft