Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Feb 14, 2014 @ 11:11
    Nicky Christensen
    0

    Get an error when nothing is chosen in ContentPicker

    Im getting an error on a contentpicker, when nothing is chosen in the contentpicker - The problem is that no matter what, the contentpicker always returns something:

    If nothing is chosen in the contentpicker, then it still returns " umbraco.MacroEngines.DynamicXml " - So that means i can't check to see if it's empty, because it never is... So how do I do this? 

    var node = Library.NodeById(page.planetLink);
                        var graphic = page.Media("planetGraphic", "umbracoFile");
                        var gWidth = page.Media("planetGraphic", "umbracoWidth")+"px";
                        var gHeight = page.Media("planetGraphic", "umbracoHeight")+"px";
                        var gPositionX = page.planetXPosition+"px";
                        var gPositionY = page.planetYPosition+"px";
                        var gZindex = page.zIndex;
                        var planetTitle = page.planetTitle;
    
                        if (!string.IsNullOrEmpty(page.GetPropertyValue("planetLink")))
                        {
                             <div class="planet" style="width: @gWidth; height: @gHeight; position:absolute; top: @gPositionX; left:@gPositionY; z-index:@gZindex;">
                                <a href="@node.Url">
                                    <img src="@graphic" width="@gWidth" height="@gHeight" alt="@planetTitle" title="@planetTitle" />                        
                                </a>
                            </div>
    
                        }
                        else
                        {
                           <div class="planet" style="width: @gWidth; height: @gHeight; position:absolute; top: @gPositionX; left:@gPositionY; z-index:@gZindex;">
                                <img src="@graphic" width="@gWidth" height="@gHeight" alt="@planetTitle" title="@planetTitle" />                        
                            </div>
                        } 
  • Nicky Christensen 76 posts 166 karma points
    Feb 14, 2014 @ 11:57
    Nicky Christensen
    0

    I solved it... I just moved the "var node..... into the if"

    The solution: 

                        var graphic = page.Media("planetGraphic", "umbracoFile");
                        var gWidth = page.Media("planetGraphic", "umbracoWidth")+"px";
                        var gHeight = page.Media("planetGraphic", "umbracoHeight")+"px";
                        var gPositionX = page.planetXPosition+"px";
                        var gPositionY = page.planetYPosition+"px";
                        var gZindex = page.zIndex;
                        var planetTitle = page.planetTitle;
    
                        if (page.HasValue("planetLink"))
                        {
                            var node = Library.NodeById(page.planetLink);
                            <div class="planet" style="width: @gWidth; height: @gHeight; position:absolute; top: @gPositionX; left:@gPositionY; z-index:@gZindex;">
                                <a href="@node.Url">
                                    <img src="@graphic" width="@gWidth" height="@gHeight" alt="@planetTitle" title="@planetTitle" />                        
                                </a>
                            </div>
                         }
                         else
                         {
                             <div class="planet" style="width: @gWidth; height: @gHeight; position:absolute; top: @gPositionX; left:@gPositionY; z-index:@gZindex;">
                                <img src="@graphic" width="@gWidth" height="@gHeight" alt="@planetTitle" title="@planetTitle" />                        
                            </div>
                         }
  • Mike Chambers 636 posts 1253 karma points c-trib
    Feb 14, 2014 @ 12:21
    Mike Chambers
    0
    if (node.GetType() != typeof(DynamicNull)){....}

    can check for those dynamicNull return types.

Please Sign in or register to post replies

Write your reply to:

Draft