Copied to clipboard

Flag this post as spam?

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


  • Mitra 81 posts 196 karma points
    Oct 01, 2014 @ 11:23
    Mitra
    0

    if else Statement

    Hello,

    I work with Umbraco and am not familiar to kentico. But now at work i have to fix something for another website.in the page, they want an a tag do nothing if there is no link, meaning doesn't open another page or anything else. I found the code and it's in document type, an ASCX file. I just need to put a condition that if there is nothing under the link, then do nothing. but the problem is this if statement doesn't work. I have change it to different formats but it doesn't realise the link is empty.

    Does anyone know if there is another kind of if statement or condition which will recognise the empty field?

     <%  string url = Convert.ToString(Eval("URL"));   
         if(!string.IsNullOrEmpty(url)){ %>
          <a href='http://<%# Eval("URL") %>' target='_blank'><%# Eval("Title") %></a>
     <% } else { %>
    
         <a href='' onclick='return false;'><%# Eval("Title") %></a>
     <% } %> 
    
  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Oct 01, 2014 @ 15:22
    Andy Butland
    1

    If this is for Kentico probably best on their forums... but I think the problem you are having is that you are binding the Eval("URL") statement - i.e. with the <%# %> brackets but also attempting to read it as presumably the property of the page - in the first line.  I'm guessing now as to how Kentico works, but thinking back to when I used web forms, this type of thing is best done in the code behind, in an "ItemDataBound" event.

    Andy

  • Mitra 81 posts 196 karma points
    Oct 02, 2014 @ 10:52
    Mitra
    0

    Thanks Andy. I think you are right about putting the statement in the code behind, in ItemDataBound event. but i am not sure where it is. I submitted my question in kentico forum. let's see if i'll get any answer.

    Thanks a lot anyway.

    regards, Mitra

Please Sign in or register to post replies

Write your reply to:

Draft