Try our conversational search powered by Generative AI!

Manoj Kumar
Aug 30, 2011
(0 votes)

Inline or Code Behind - EPI Server Property

I have a requirement where a product price is selected based of discount flag setting done by web admin in edit mode. I have three property's “Normal Price”, “Promotional Price” and a flag “For sale”. if “for sale” is on then the promotional price should be shown other wise normal price should be shown.  I found two ways to work on this issue inline or code behind.


Code Behind :-

For code behind I created a property and made a check in get assessor of the property -


 public int Price
                PropertyData property = CurrentPage.Property["StockStatus"];

                if (property.ToString().ToLower() == "forsale")
                    PropertyData property22 = CurrentPage.Property["PromotionalPrice"];
                    if (property22 != null && !property22.IsNull)
                        _price = Convert.ToInt32(property22.ToString());
                    PropertyData property22 = CurrentPage.Property["ProductPrice"];
                    if (property22 != null && !property22.IsNull)
                        _price = Convert.ToInt32(property22.ToString());

                return _price;


Only html at UI is-
<% = Price %>



Inline Code:-

Below is the straight forward inline code -


<% if (CurrentPage.Property["StockStatus"].ToString().ToLower() == "forsale")
   { %>
       <%=  CurrentPage.Property["PromotionalPrice"].ToString() %>
<% }
   { %>
         <%= CurrentPage.Property["ProductPrice"].ToString() %>
<% } %>
Aug 30, 2011


Magnus Rahl
Magnus Rahl Aug 30, 2011 02:41 PM

To "ToString" the properties directly is dangerous - they could be null. Get a string property like this (DefaultValue could be anything you like):

CurrentPage["StockStatus"] as string ?? DefaultValue

Eric Aug 31, 2011 12:39 PM

or use Convert.String could be used i think that will returns string.empty if i remember correctly if null..

Manoj Kumar
Manoj Kumar Sep 5, 2011 09:44 AM

Yes using "ToString" directly is dangerous. Further on best practice of property usage go to online cms sdk.

- Developers Guide
- Core Features
- Properties
- Working With Page Properties in EPiServer CMS

Please login to comment.
Latest blogs
Introducing Image Transformer - AI Assistant for Optimizely

We've got something super cool to share with you, and it's all about giving your images a fresh spin. Image Transformer, the latest feature from ou...

Luc Gosso (MVP) | Feb 26, 2024 | Syndicated blog

Welcome 2024 Winter OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Feb 26, 2024

Optimizely Opal... what it does actually do?

At Opticon 2023, Optimizely announced its first AI product Opal. AI is definitely the new tech buzzword in 2024 and with promises that AI will be...

Jon Jones | Feb 25, 2024 | Syndicated blog

How to add more Content Area Context Menu Item in Optimizely CMS 12

Hey folks, today I will share something related to Context Menu customization in the Content Area of Optimizely CMS. As you know, the content area ...

Binh Nguyen | Feb 25, 2024

Developer meetups in Stockholm & Helsinki

It's time for developer meetups! Next month we will be in Stockholm and Helsinki. Join us for getting the latest updates from Optimizely, be inspir...

Magnus Kjellander | Feb 23, 2024

Roll Your Own Security Headers

Proper security headers are a must for your Optimizely driven website. There are a variety of tools out there that will help with this, but when...

Ethan Schofer | Feb 21, 2024