IfEmpty in ASCX template

Conor Dunk asked on November 15, 2016 13:27

Apologises if i'm covering old ground.

I'm trying to use the IfEmpty method below without any success.

<%# IfEmpty(CurrentDocument.GetValue("OnlineGetQuoteLink"), "empty", "not empty"))%>

any help would be greatly appreciated.

Recent Answers


Brenden Kehren answered on November 15, 2016 14:11 (last edited on November 15, 2016 14:11)

So what's the problem?

Keep in mind if you're using CurrentDocument this will return value(s) from the actual page you are navigating to vs. using Eval("") which will return data from the dataset you are getting data from which could be a totally different node in the content tree. So maybe you want/need to use Eval("OnlineQuoteLink") instead.

0 votesVote for this answer Mark as a Correct answer

Conor Dunk answered on November 15, 2016 16:06

Thanks for responding Brandon,

I still get this error: The name 'IfEmpty' does not exist in the current context

Now using <%# IfEmpty(Eval("OnlineGetQuoteLink"), "No image", "not empty") %>

Thank you, Conor

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 15, 2016 16:25 (last edited on November 15, 2016 18:40)

Sorry, missed the title, you cannot use this in a template, this method, IfEmpty() is only available in a transformation, not templates. You'd have to use standard C# or fully namespace the method.

1 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on November 15, 2016 18:04

Hi Conor,

You can use IfEmpty method in ASPX template:

<%# CMS.Controls.TransformationHelper.HelperObject.IfEmpty(...) %>

or

<%@ Import Namespace="CMS.Controls" %>
<%# TransformationHelper.HelperObject.IfEmpty(...) %>
2 votesVote for this answer Mark as a Correct answer

Adam Gitin answered on November 16, 2016 10:32 (last edited on November 16, 2016 10:33)

can try short IF

<%# CurrentDocument.GetValue("OnlineGetQuoteLink").ToString() = "" ? "empty":"not empty" %>

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.