Newbie property question



I'm just starting developing using CMS 5 and I want to add a custom property to a Label:

<asp:Label ID="myId" runat="server" Text='<%= CurrentPage["myproperty"] %>' ></asp:Label> 

If this is possible, could you please tell me what I'm doing wrong in the code above!?

Jun 11, 2008 10:37

<asp:Label ID="myId" runat="server" Text='<%# CurrentPage["myproperty"] %>' ></asp:Label> 

Jun 11, 2008 11:13
And don't forget to call myId.DataBind().
Jun 11, 2008 11:26

Thanks for your fast replies!

It works beautifully but I now got a followup question:

I now have a page that looks like this:

<asp:Label ID="myId" runat="server" Text='<%# CurrentPage["myproperty"] %>' ></asp:Label> 


<EPiServer:Property PropertyName="myproperty" ID="myId2" runat="server" />

When I browse the page, rightclick and choose Edit (Ändra) I'm only able to edit the value of myId2. Is there a workaround for this?

Jun 11, 2008 11:57

No. Only EPiServer:property supports on page edit.

Is there a reason as to why couldn't use episerver:property for both properties?

Jun 11, 2008 14:44

A workaround to this problem is to use

<EPiServer:Property PropertyName="myproperty" ID="myId2" runat="server" />

as you wrote in your post.

And you can read more about EPiServer web controls and dope in the document below.

Jun 11, 2008 15:08

I have created a usercontrol with attributes that I want to set. So it looks like this:

<uc2:MyUserControl ID="MyControl" runat="server" MyAttribute='<%# CurrentPage["myproperty"] %>'  />

Is there a way to use the EPiServer:property to set the 'MyAttribute' on the usercontrol?

Jun 11, 2008 15:10

Not exactly - you cannot nest controls within attributes of another control. I'd have to ask exactly why you want to do this though - it's not a good idea really. An EPiServer property can contain pretty much anything and I don't think you'd really want it writing out information like HTML into an attribute?

If you have to do something like this then can you not just use an EPiServer property control so that you see it in edit mode but just hide it on the View Mode page? That way you can edit it in Edit Mode and use the data as well.

 I suspect that a bit of re-architecting might give you a much cleaner and more powerful solution though.

- Dan

Edited, Jun 11, 2008 16:48

Thanks again for all your input!

I really want to see if I can get this working before looking into re-architecting the site. I have come one step further:

1) I have now placed an <EPiServer:Property> inside the UserControl.
2) On the aspx-page containing the UserControl I specify the propertyname for <EPiServer:Property> (inside the UserControl).

Doing this I am now able to edit the text by rightclicking and choose Edit. However, when I click Save the value never gets saved.

Jun 12, 2008 10:28
Oops, forgot to clarify: I specify the propertyname in the aspx Page_Load function Smile
Jun 12, 2008 10:31

I got it all working now, thanks for your help!!!

Jun 12, 2008 14:12
* 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.