Try our conversational search powered by Generative AI!

Get text from a XHTML-string in EditMode

Vote:
 

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);

#42477
Aug 25, 2010 10:15
Vote:
 

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).

#42481
Aug 25, 2010 10:54
Vote:
 

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

#42483
Aug 25, 2010 11:11
Vote:
 

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.

#42484
Aug 25, 2010 11:12
Vote:
 

What is the diffrence?

#42486
Aug 25, 2010 11:19
Vote:
 

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

#42487
Edited, Aug 25, 2010 11:22
Vote:
 

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?

#42488
Edited, Aug 25, 2010 11:24
Vote:
 

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.

#42490
Aug 25, 2010 11:50
Vote:
 

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

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

#42493
Aug 25, 2010 11:55
Vote:
 

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.

#42494
Aug 25, 2010 11:56
Vote:
 

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

PageBase pb = (PageBase)this.Page;
pb.SavePage();

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.

#42495
Aug 25, 2010 12:11
Vote:
 

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]"];
SetValuesForPropertyControls([idOfPropertyControl]);
DataFactory.Instance.Save(writeableClone....

#42496
Aug 25, 2010 12:27
Vote:
 

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

#42498
Aug 25, 2010 12:34
Vote:
 

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

var clone = CurrentPage.CreateWritableClone();
mainBody.PropertyValue.Equals(clone.Property["MainBody"]);
SetValuesForPropertyControls(mainBody);
DataFactory.Instance.Save(clone, SaveAction.Publish, AccessLevel.NoAccess); 

#42499
Aug 25, 2010 12:39
Vote:
 

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.

#42500
Aug 25, 2010 12:42
Vote:
 

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?

#42501
Aug 25, 2010 12:45
Vote:
 

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?

#42502
Aug 25, 2010 12:47
Vote:
 

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

#42503
Aug 25, 2010 12:49
Vote:
 

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... :(

#42504
Aug 25, 2010 12:52
Vote:
 

Check out this thread http://world.episerver.com/Templates/Forum/Pages/thread.aspx?id=19369&pageindex=1 it could be the javascript issue.

#42505
Aug 25, 2010 13:01
Vote:
 

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

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