Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Get text from a XHTML-string in EditMode


I've got an XHTML-string (e.g. MainBody) that is displayed in edit mode by using <EPiServer:Property PropertyName="MainBody" runat="server" ID="mainBody" EditMode="true" />. This will of course then be used to update the MainBody-property on that page. My question is what I use to get the changes from the property that needs to be saved. How do I get a hold of what the WYSIWYG contains? How do I complete the second row of the code below?

PageData updatedPage = oPage.GetPage(new PageReference(CurrentPage.PageLink.ID)).CreateWritableClone();
updatedPage.Property["MainBody"].Value = mainBody...
DataFactory.Instance.Save(updatedPage, SaveAction.Publish, AccessLevel.NoAccess);

Aug 25, 2010 10:15

In my experience this can be rather tricky to accomplish. A good start is if you only want to edit pages, not create new ones.

Judging by your property control declaration it looks like you are editing the property on the page itself, are you? In that case you should be able to just call SavePage (inherited from PageBase) to save all property changes.

If you are trying to edit a property from a different page than the one displayed, please reply so and I will try to go through the steps needed (I can't from the top of my head right now).

Aug 25, 2010 10:54

I am trying to edit the property on the current page. I read something about DOPE mode? Could this be it?

Aug 25, 2010 11:11

If your goal is to edit the current page, DOPE could be for you. But if you want to use a more customized mode of editing the current page, using property controls is one way to go.

Aug 25, 2010 11:12

What is the diffrence?

Aug 25, 2010 11:19

DOPE is a predefined mode (quick-edit in the EPiServer context menu) which edits ALL property controls visible on the page. Sometimes you might only want to edit some properties this way, or you don't use property controls to render the properties, in which case they won't be possible to edit in DOPE mode.

Edit: The individual properties can also render in a different way in DOPE mode than in edit mode

Edited, Aug 25, 2010 11:22

I would like to use the property controls to edit two properties, by adding EditMode="True" to these two properties. What would be the best way to go about and how do I do this?

Edited, Aug 25, 2010 11:24

All you have to do is to declare the properties like you did in the aspx and then call SavePage() in your click event handler.

Aug 25, 2010 11:50

I can't figure out how to declare to MainBody.

updatedPage.Property["MainBody"].Value = mainBody...

Aug 25, 2010 11:55

Don't. You dont have to do any of that. SavePage() will automatically scan your page for property edit controls, create a writeable clone of the current page, save the properties and save a new page version with the properties changed.

Aug 25, 2010 11:56

I can't get it to work. Is this all my "Save"-button should contain?

PageBase pb = (PageBase)this.Page;

Does it PostBack before it saves? At first I got an error message because I set CausesValidation="False" but when setting it to True the code runs but the changes are ignored.

Aug 25, 2010 12:11

Are you changing the control collection depending on wheter it is a postback or not, is that why you ask? For the property controls to retain their values after postback (which is caused by the click event) they have to be loaded with the same ID:s etc. That shouldn't be a problem if you added them to the aspx.

Anyway, any more luck if you try to do something like this?

var clone = CurrentPage.CreateWriteableClone();
[idOfPropertyControl].PropertyData = clone.Property["[PropertyName]"];

Aug 25, 2010 12:27

I can't get that code to compile... :/

Aug 25, 2010 12:34

If this is how you ment it then no, same problem:

var clone = CurrentPage.CreateWritableClone();
DataFactory.Instance.Save(clone, SaveAction.Publish, AccessLevel.NoAccess); 

Aug 25, 2010 12:39

Yes, that's how.

My guess is that there is something in the page cycle which prevents the framework from setting the posted values to the controls. It could be that you do some manipulation of where controls are placed, when they are rendered and not or something else which prevents the framework from finding the same controls after postback. Or some Databind statement somwhere which puts the old values back into the property controls before you try to save the page.

Aug 25, 2010 12:42

I have a button on the page that says "Edit" that performs a PostBack and changes the MainBody-property to an editable one. Is this what causes it?

Aug 25, 2010 12:45

I have a button on the page that says "Edit" that performs a PostBack and changes the MainBody-property to an editable one. Is this what causes it?

Aug 25, 2010 12:47

I just tried removing that function to always displaying it in EditMode and still the same problem. It ignores the changes.

Aug 25, 2010 12:49

I have no further suggestions then... I would have to try to do it myself and I don't have the time right now, sorry... :(

Aug 25, 2010 12:52

Check out this thread it could be the javascript issue.

Aug 25, 2010 13:01

I understand! I'm going to look into the whole PostBack-thing some more. Thanks!

Aug 25, 2010 13:06
* 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.