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

Forums / Developing with Sitefinity / How to check if a value is empty?

How to check if a value is empty?

3 posts, 0 answered
  1. Marz
    Marz avatar
    7 posts
    Registered:
    29 Aug 2012
    02 Nov 2012
    Link to this post
    Hi,

    I want to show a list of my events. I want to show their Title, Start Date/End Date, Registration link and Registration Status (status can be Open, Coming Soon, Closed and Sold Out).

    I am using a different AMS system to generate and manage my registrations, I just want to embed a link in my event pages in Sitefinity.  In order to do so, I created a new 'Custom Field' for embedding my Registration Link and also created another 'Custom Field' for my event Status.  Everything is working fine expect one thing.  I want the Registration Status to be hyperlinked if the Status is 'Open', in other words: IF the 'Custom Field' for URL has a value, then hyperlink the value (link) to Status (Open) and if the custom field is empty and other statuses are selected, then only show the status (Coming Soon, Sold Out, Closed) with no hyperlink of course.

    This is the code I am using in my Widget Template:

    <div class="Registration">
    <a href="<%# Eval("OnlineRegistration")%>"><%# Eval("RegistrationStatus")%></a>
    </div>

    Is there any way to turn the href value on or off bases on the existence of the URL?

    Thanks

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    02 Nov 2012
    Link to this post
    Ok, I'm winging this in the editor, so exuse any potential typos, but logic works...just toggle visibility based on String.IsNullOrEmpty

    Change out your <a> to this
    <asp:HyperLink runat="server" NavigateUrl='<%# Eval("OnlineRegistration")%>' Text='<%# Eval("RegistrationStatus")%>' Visible='<%# !String.IsNullOrEmpty(Eval("OnlineRegistration").ToString()) %>' />


    ...or runat=server the div and but the visible up there.

    ...or maybe change the navurl to a pound if empty

    <asp:HyperLink runat="server" NavigateUrl='<%# !String.IsNullOrEmpty(Eval("OnlineRegistration").ToString()) ? Eval("OnlineRegistration").ToString() : "#" %>' Text='<%# Eval("RegistrationStatus")%>' />

  3. Marz
    Marz avatar
    7 posts
    Registered:
    29 Aug 2012
    02 Nov 2012 in reply to Steve
    Link to this post
    Steve,

    Thanks.  The first block of code just clears the status and it shows nothing.  It just shows an empty box.  I want to show the status but if the Status has no available hyperlink then unlink the status and just show text.

    The second block, kinda works (although I prefer not to have a hyperlink for non-open statuses).  It adds a '#' sign along with this text: SfCtrlPresentation to the URL.  So, my URL changes to something like this: "http://localhost/SfCtrlPresentation/#" which returns a 404 when you click it.

    Thanks
3 posts, 0 answered