Check if custom page field is empty

Carson Wong asked on July 12, 2016 19:31

Hi,

In a transformation, I am trying to check if a custom page field is empty. Currently, I've tried the following:

<% if(Eval("Custom_Page_Field") != ""){ %>
<% } %>

and

<% if(Eval("Custom_Page_Field") != null){ %>
<% } %>

And both are not working for me.

Correct Answer

Brenden Kehren answered on July 12, 2016 19:44

Try casting the object like so:

Eval<string>("FieldName") == ""

Or

IfEmpty(Eval<string>("FieldName"), true, false)

Or

ValidationHelper.GetString(Eval("FieldName"), "") == ""

Or

Eval("FieldName").ToString() == ""
0 votesVote for this answer Unmark Correct answer

Recent Answers


Carson Wong answered on July 12, 2016 19:47

@Brenden Thank you. I did not know that Eval() did not return a String... It works now, thank you for your help!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 12, 2016 23:24

Eval("FieldName") by default returns an object. In most cases, we get lucky and the control rendering the data can type it out. In some cases you have to tell it what type you're working with.

0 votesVote for this answer Mark as a Correct answer

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