Copied to clipboard

Flag this post as spam?

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


  • Fredrik 89 posts 108 karma points
    Mar 03, 2011 @ 14:04
    Fredrik
    0

    Problem finding property by name .NET

    I have a ajax autocomplete textbox on my umbracopage which has been working fine comparing prefixtext agains two properties from my documenttype.

    However, yesterday I added a third property to compare against and this is where the problem comes in.

     

    Following code works fine

    Node node = new umbraco.presentation.nodeFactory.Node(1079);
                foreach (Node child in node.Children)
                {
                    foreach (Node child2 in child.Children)
                    {
                        foreach (Node child3 in child2.Children)
                        {
                            if (child3.NodeTypeAlias == "Product" && child3.GetProperty("name").Value.ToUpper().Contains(prefixText.ToUpper())
                                || child3.NodeTypeAlias == "Product" && child3.GetProperty("articleNr").Value.ToUpper().Contains(prefixText.ToUpper()))
                            {
                                namn.Add(child3.GetProperty("articleNr").Value +  "-" + child3.Name);

                            }

                            foreach (Node child4 in child3.Children)
                            {
                                if (child4.NodeTypeAlias == "Product" && child4.GetProperty("name").Value.ToUpper().Contains(prefixText.ToUpper())
                                || child4.NodeTypeAlias == "Product" && child4.GetProperty("articleNr").Value.ToUpper().Contains(prefixText.ToUpper()))
                                {
                                    namn.Add(child4.GetProperty("articleNr").Value + "-" + child4.Name);
                                }

                            }
                        }
                    }

                }

     

    However if I add my newly created property(keys) as a third condition the whole ajax autocomplete fails in showing anything at all.

    Like this.

    if (child3.NodeTypeAlias == "Product" && child3.GetProperty("name").Value.ToUpper().Contains(prefixText.ToUpper())
       || child3.NodeTypeAlias == "Product" && child3.GetProperty("articleNr").Value.ToUpper().Contains(prefixText.ToUpper())
    || child3.NodeTypeAlias == "Product" && child3.GetProperty("keys").Value.ToUpper().Contains(prefixText.ToUpper()))

    the property keys is a textstring just like name and articleNr

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 03, 2011 @ 14:12
    Dirk De Grave
    0

    Did you add the third property afterwards? If so, it may not yet be in your published xml for each of the "Product" documents, hence failing on the .GetProperty("keys") which will return null, so .Value will raise the exception.

    Republish your site to make sure all "Product" docs have this property published as well.

     

    If that doesn't work, fire up your debugger and see why it's failing by adding a try/catch and inspecting the exception thrown.

     

    Cheers,

    /Dirk

     

  • Fredrik 89 posts 108 karma points
    Mar 03, 2011 @ 14:25
    Fredrik
    0

    Yes, it was added afterwards.

    I have over 100 products....do I have to republish each of these one by one? Or is there another way of doing it? 

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 03, 2011 @ 14:53
    Dirk De Grave
    0

    yup, go to /umbraco/dialogs/republish.aspx?xml=true and hit Refresh to regenerate the published xml.

     

    Cheers,

    /Dirk

  • Fredrik 89 posts 108 karma points
    Mar 03, 2011 @ 15:06
    Fredrik
    0

    Great work Dirk, it works perfectly now!

Please Sign in or register to post replies

Write your reply to:

Draft