Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
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>
<% } %>
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.
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.
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 %>
Ok, thank you very much for your help. I try it out tomorrow and mark your post as answer.
Have a nice day.
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?
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.
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!!
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!