Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:17:07+00:00 2026-06-10T09:17:07+00:00

I am using ugc conditional statement in my code, the equals condition is working

  • 0

I am using ugc conditional statement in my code, the equals condition is working fine, but how can be used other conditional operator like “>” “<” and “Not Equals”.

<%
HttpContext.Current.Items["CommentCount"] = 0;
%>

<ugc:Choose runat="server">
  <ugc:When test="ugcItemStats.numberOfComments > CommentCount" runat="server">
         HTML1
  </ugc:When>
  <ugc:Otherwise runat="server">
         HTML2
  </ugc:Otherwise>
</ugc:Choose>

What operator should be used, if numberofComments is greater than 0, I tried like this way and also tried “notequals” instead of “>” but its does’t work.

Please suggest

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:17:08+00:00Added an answer on June 10, 2026 at 9:17 am

    Tridion ug:when will be work only with ” equal ” and “==” if you want to use other operator then you have to create the other customer control for this.

    I have created and i hope it will be work with “==,>=”,<=,>,<,!=” operator.

    its working in my project.

    using System;
    using System.ComponentModel;
    using System.Globalization;
    using System.Reflection;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.UI;
    
    namespace Tridion.ContentDelivery.UGC.Web.UI
    {
        [DefaultProperty("Test"), ToolboxData("<{0}:WhenCond runat=server></{0}:WhenCond>"), ParseChildren(ChildrenAsProperties = false)]
        public class WhenCond : BaseUGCServerControl
        {
            private string test;
            private static Regex pattern = new Regex(@"\.");
            protected virtual bool Condition()
            {
                if (this.test == null)
                {
                    return false;
                }
                string[] sep = new string[] { "==", "<", ">", "<=", ">=" ,"!="};
                string[] testArray = test.Split(sep, StringSplitOptions.None);
                if (testArray.Length == 2)
                {
                    object value1 = EvaluateVariable(testArray[0].Trim(), HttpContext.Current);
                    object value2 = EvaluateVariable(testArray[1].Trim(), HttpContext.Current);
                    if (value1 != null && value2 != null)
                    {
                        if (isNumeric(value1.ToString(), NumberStyles.Number) && isNumeric(value2.ToString(), NumberStyles.Number))
                        {
                            return NumericCondition(double.Parse(value1.ToString()), double.Parse(value2.ToString()), GetSepartor());
                        }
                        else
                        {
                            return AlphaNumericCondition(value1.ToString(), value2.ToString(), GetSepartor());
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                return false;
            }
    
            public static object EvaluateVariable(string varProperty, HttpContext usedContext)
            {
                if (!string.IsNullOrEmpty(varProperty))
                {
                    string[] strArray = pattern.Split(varProperty);
                    if (!string.IsNullOrEmpty(strArray[0]))
                    {
                        object obj2 = usedContext.Items[strArray[0]];
                        if (obj2 != null)
                        {
                            object obj3 = obj2;
                            for (int i = 1; i < strArray.Length; i++)
                            {
                                if (obj3 != null)
                                {
                                    string str = strArray[i];
                                    if (!string.IsNullOrEmpty(str))
                                    {
                                        string str2 = str.Substring(0, 1);
                                        string str3 = str.Substring(1);
                                        string name = str2.ToUpper() + str3;
                                        PropertyInfo property = obj3.GetType().GetProperty(name);
                                        if (property != null)
                                        {
                                            obj3 = property.GetValue(obj3, null);
                                        }
                                    }
                                }
                            }
                            return obj3;
                        }
                    }
                }
                return null;
            }
    
            public bool isNumeric(string val, System.Globalization.NumberStyles NumberStyle)
            {
                Double result;
                return Double.TryParse(val, NumberStyle, System.Globalization.CultureInfo.CurrentCulture, out result);
            }
    
            private string GetSepartor()
            {
                string sept = string.Empty;
                sept = this.test.Contains("==") ? "==" : string.Empty;
                sept = string.IsNullOrEmpty(sept) ?(this.test.Contains(">") ? ">" : string.Empty):sept;
                sept = string.IsNullOrEmpty(sept) ? (this.test.Contains("<") ? "<" : string.Empty) : sept;
                sept = string.IsNullOrEmpty(sept) ?(this.test.Contains(">=") ? ">=" : string.Empty):sept;
                sept = string.IsNullOrEmpty(sept) ?(this.test.Contains("<=") ? "<=" : string.Empty):sept;
                sept = string.IsNullOrEmpty(sept) ? (this.test.Contains("!=") ? "!=" : string.Empty) : sept;
                return sept;
            }
    
            private bool NumericCondition(double value1, double value2, string sept)
            {
                bool returnFlag = false;
                switch (sept)
                {
                    case "==":
                        returnFlag = (value1 == value2);
                        break;
                    case ">":
                        returnFlag = (value1 > value2);
                        break;
                    case "<":
                        returnFlag = (value1 < value2);
                        break;
                    case ">=":
                        returnFlag = (value1 >= value2);
                        break;
                    case "<=":
                        returnFlag = (value1 <= value2);
                        break;
                    case "!=":
                        returnFlag = (value1 != value2);
                        break;
                }
                return returnFlag;
            }
    
            private bool AlphaNumericCondition(string value1, string value2, string sept)
            {
                bool returnFlag = false;
                switch (sept)
                {
                    case "==":
                        returnFlag = (value1.CompareTo(value2) == 0);
                        break;
                    case "!=":
                        returnFlag = (!value1.Equals(value2));
                        break;
                    case ">":
                        returnFlag = (value1.CompareTo(value2) > 0);
                        break;
                    case "<":
                        returnFlag = (value1.CompareTo(value2) < 0);
                        break;
                }
                return returnFlag;
            }
    
            protected override void Render(HtmlTextWriter writer)
            {
                if ((HttpContext.Current != null) && (HttpContext.Current.Application != null))
                {
                    Control parent = this.Parent;
                    if (!(parent is Choose))
                    {
                        throw new InvalidOperationException("WhenCond control must have a Tridion Web UI Choose server control as parent!!!");
                    }
                    Choose choose = (Choose)parent;
                    if (!choose.AlreadyMatchedCondition() && this.Condition())
                    {
                        choose.MatchedCondition();
                        this.RenderChildren(writer);
                    }
                }
            }
    
            [Category("Appearance"), DefaultValue(""), Bindable(true)]
            public string Test
            {
                get
                {
                    return this.test;
                }
                set
                {
                    this.test = value;
                }
            }
        }
    }
    

    implementaion in aspx page

    <%@ Register assembly="Tridion.Custom.Web.UI" namespace="Tridion.ContentDelivery.UGC.Web.UI" tagprefix="cc1" %>
    
    
    <ugc:Choose runat="server">
      <cc1:WhenCond test="ugcItemStats.numberOfComments > CommentCount" runat="server">
             HTML1
      </cc1:WhenCond>
      <ugc:Otherwise runat="server">
             HTML2
      </ugc:Otherwise>
    </ugc:Choose>
    

    if you face any problem please let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using UGC feature of Tridion 2011. I have done almost but stuck
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
using this code I can send one texture to the shader: devcon->PSSetShaderResources(0, 1, &pTexture);
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
using prototype method we can create new methods... like... Object.prototype.newMethod=function(){ // do something }
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Using Rails 3.2.0 with haml and sass: I Would like to link an external
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using jQuery, one can easily find out whether a particular element is visible using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.