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

Forums / Sitefinity SDK / How do I do conditional Visibility in a widget?

How do I do conditional Visibility in a widget?

9 posts, 1 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    19 Feb 2011
    Link to this post
    What am I doing wrong here...

    <asp:Image runat="server" ImageURL='<%# Eval("ImageURL")%>'  Visible= '<%# (String.IsNullOrEmpty(Eval("ImageURL")) ? "False" : "True" %>'  EnableViewState="False"   />

    Trying to toggle the visibility of widget content if it's empty...

    Doesn't seem to work though...

    Also tried to do something similar by conditionally setting the CSS class, but that didn't work either
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    22 Feb 2011
    Link to this post
    Hi Steve,

    If you use our template parser this will not work. Is this a user or custom control compiled to a dll?

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    22 Feb 2011
    Link to this post
    It's the Blog List View, trying to edit the widget template to only show an image if there is one.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    22 Feb 2011
    Link to this post
    Hello Steve,

    In this case our template parser is used an it does not work with these expressions. You can hide the image with server side code.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  5. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    22 Feb 2011
    Link to this post
    I'm trying to do this without having to build custom controls...

    So I think I can do it by adding a new custom field called like ShowImage (bit field) and set that to the visibility property?

    Question though is how can I create a bit property...last time I tried it created it as bit(255) and OA killed the site trying to create a bit column with 255 length.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    28 Feb 2011
    Link to this post
    Hello Steve,

    If you use Unknown type for the field you can set it to BIT. Another option is True/False field.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
    Answered
  7. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 Feb 2011
    Link to this post
    I'm still having issues with this...if the templates can't do conditional

    The only thing I can think to do is expose a textfield whos content is inside a style tag on a div (so I could specify display:none in the textbox)

    So that's easy for me to do, but not so easy for an admin to remember (even with the instructional text assigned)

    Will the parser ever be expanded to allow the conditional statements?
    Visible= '<%# (String.IsNullOrEmpty(Eval("ImageURL")) ? "False" : "True" %>'

    I'll do the text input for now :)
  8. Miles
    Miles avatar
    32 posts
    Registered:
    23 Nov 2011
    12 Jan 2012
    Link to this post
    I'm hoping someone will reply soon with an answer to this or at least an update.

    The conditional statement would be wonderful if supported (I'm doing the same thing you are with a button). There's no need to write a server side control just to control the visibility (or some property with two values).
  9. Richard
    Richard avatar
    64 posts
    Registered:
    09 Oct 2012
    15 Oct 2013
    Link to this post
    We're now in version 6.1. Is it possible to do Conditional Visibility? I have created a custom module that has a 'website' field. On my widget template I have a button that says 'visit website' the button will use whatever was entered in the 'website' field as the link. if no website was entered I don't want to show the button. I actually need this functionality on most of my custom modules. Sometimes I need to change the plurality based on what is entered in a field. I need a way to do if/else statements in the template.
9 posts, 1 answered