Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Jan 12, 2010 @ 16:01
    Lee
    0

    Checking Request For Null?

    Hey everyone - Having a weird problem, I'm getting a posted value into a variable like so

    <xsl:variable name="thedate" select="umbraco.library:Request('DateTo')"/>

    Now if there is a value I want to populate a textbox, if no value I just want to put some default text in - But the below doesn't work?  It never triggers the otherwise statement even though there is no posted value for $thedate?  Any ideas where I am going wrong?

    <xsl:choose>
              <xsl:when test="$thedate != '' or $thedate != 'Date To' or $thedate != 'NaN'">
                <input class="forminput" title="Date To" id="DateTo" name="DateTo" type="text" value="{$thedate}" />
              </xsl:when>
              <xsl:otherwise>
                <input class="forminput" title="Date To" id="DateTo" name="DateTo" type="text" value="Date To" />
              </xsl:otherwise>
    </xsl:choose>

    ???

  • dandrayne 1138 posts 2262 karma points
    Jan 12, 2010 @ 16:05
    dandrayne
    0

    You could try casting to a string and then check for '' ?  IIRC, it should turn NULL into an empty string

    Worth a shot!

    string($thedate) != ''

     

  • Lee 1130 posts 3088 karma points
    Jan 12, 2010 @ 16:12
    Lee
    0

    Hey Dan - I tried that initially and its exactly the same??  Any other ideas??

  • Jesper Hauge 298 posts 487 karma points c-trib
    Jan 12, 2010 @ 16:44
    Jesper Hauge
    0

    I'd check up on what is actually coming back from the umbraco.library:Request() call by inserting a 

    <xsl:copy-of select="$thedate" />

    In the code and then running the page with and without the request variable just to check.

    According to reflector the code of the library:Request call is:

    public static string Request(string key)
    {
        if (HttpContext.Current.Request[key] != null)
        {
            return HttpContext.Current.Request[key];
        }
        return string.Empty;
    }
    

    which probably means that $thedate = '' when the key isn't present or there is no value for the request key. In all other cases it will return some kind of string content.

    Regards
    Jesper Hauge

Please Sign in or register to post replies

Write your reply to:

Draft