Try our conversational search powered by Generative AI!

Take a value from a property, mix with it and write it on page


Hi all!

I have a question.

Let say I have a pagetype with a property 'SiteSeekerWeightPROP' of type String (<=255). The field name to the editor is "Put a value 1-9 to set SEO for SiteSeeker".

In the pagetemplate codebehind I want 1=0.1, 2=0.2 and so on. If the property is null I want 0.5.

In the pagetemplate front code I want to write the value in the value attribute of a meta tag, like this: <meta name="..." value="[DECIMAL GOES HERE]">

How do I accomplish this? I tried a lot.

And please Iam a newbie so try to explain well.

I think this involves something like this
- a method, method_X  in the codebehind with if statements
- somewhere in codebehind I need 'get set', dont know how that works
- in front end code <meta name="..." value="<%= method_X %>">

Am I on the right track?


Thank you so much for the help!

Apr 12, 2012 18:33

I guess this would solve it (well, a meta tag instead of h2 of course), but, I want to learn more codebehind ...


<% if (CurrentPage["SiteSeekerWeightPROP"] as string == "1")
           { %>
            <h2>Weight: 0.1</h2>
        <% } %>
        <% if (CurrentPage["SiteSeekerWeightPROP"] as string == "2")
           { %>
            <h2>Weight: 0.2</h2>
        <% } %>
        <% if (CurrentPage["SiteSeekerWeightPROP"] as string == "3")
           { %>
            <h2>Weight: 0.3</h2>
        <% } %>

and so on ... to 0.9

        <% else
           { %>
           <h2>Weight: 0.5</h2>
        <% } %>

Apr 12, 2012 19:09

You could use the property "Drop-down list" instead of "String (<=255)". And have 1, 2, 3 as names and 0.1, 0.2, 0.5 as values, then you don't need to translate or validate the values the editor enters.

Apr 12, 2012 19:22

Johan: Thank you! Of course, smart. I think I make it that way. =)

But if I want to learn more about code behind, and we use this as an example. The fundamental here is to read a property from a page type, do some stuff with c#, and write something to the aspx file.

Apr 12, 2012 19:39

Yeah sure. I would make use of a switch statement:

protected string GetWieght
        switch (CurrentPage["MyProp"] as string)
            case "1":
                return "0.1";
            case "2":
                return "0.2";
            case "3":
                return "0.3";
            case "4":
                return "0.4";
                return "0.5";

  And in the aspx:

<%= this.GetWieght %>


Apr 12, 2012 19:44

Oups sorry for the spelling... GetWeight of course ;)

Apr 12, 2012 19:45

Ok, thank you very much for your help. I try it out tomorrow and mark your post as answer.

Have a nice day.

Apr 12, 2012 20:01

Just a thought I have, before going to rest my mind a bit, what if an editor types in "999" in the field in Epi? Would default trigger?

Apr 12, 2012 20:15

Yes "default" will "trigger".

But I would recomend going with the "Drop-down list" approach instead. Because then the editor can't enter any invalid values.

Apr 12, 2012 20:17

Yeah it does. Sorry Iam being lazy and asking. I tried it out here in Visual Studio using Camino server (?).

Yepp, I will go with the drop down, much more convenient for the editors. Thank you so so much for the help!!

Apr 12, 2012 20:26
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.