Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Manoj Kumar
Aug 30, 2011
  3125
(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
        {
            get
            {
                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());
                    }
                }
                else 
                {
                    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() %>
<% }
   else
   { %>
         <%= CurrentPage.Property["ProductPrice"].ToString() %>
<% } %>
Aug 30, 2011

Comments

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
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.

- http://sdk.episerver.com/library/cms6.1/index.aspx#
- Developers Guide
- Core Features
- Properties
- Working With Page Properties in EPiServer CMS

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog