Newbie property question

Vote:
 

Hi!

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

#20755
Jun 11, 2008 10:37
Vote:
 

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

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

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> 

<br>

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

#20759
Jun 11, 2008 11:57
Vote:
 

No. Only EPiServer:property supports on page edit.

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

#20770
Jun 11, 2008 14:44
Vote:
 

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.

http://world.episerver.com/Documents/the_book/07_EPiServer_Web_Controls.pdf

#20771
Jun 11, 2008 15:08
Vote:
 

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?

#20772
Jun 11, 2008 15:10
Vote:
 

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

#20773
Edited, Jun 11, 2008 16:48
Vote:
 

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.

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

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

#20793
Jun 12, 2008 14:12