London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

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

Vote:
 

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!

#58086
Apr 12, 2012 18:33
Vote:
 

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>
        <% } %>

#58087
Apr 12, 2012 19:09
Vote:
 

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.

#58088
Apr 12, 2012 19:22
Vote:
 

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.

#58089
Apr 12, 2012 19:39
Vote:
 

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

protected string GetWieght
{
    get
    {
        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";
            default:
                return "0.5";
        }
    }
}

  And in the aspx:

<%= this.GetWieght %>

    

#58090
Apr 12, 2012 19:44
Vote:
 

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

#58091
Apr 12, 2012 19:45
Vote:
 

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

Have a nice day.

#58092
Apr 12, 2012 20:01
Vote:
 

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?

#58093
Apr 12, 2012 20:15
Vote:
 

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.

#58094
Apr 12, 2012 20:17
Vote:
 

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

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