Custom "edit-mode"

Vote:
 


 Hello!
 I need some advice regarding the process of creation of the custom "Edit-mode" page. I'd like to make my own content creating/editing visual interface for, let's say, 'News' section of some site. I have an aspx-form with a set of textBoxes and som ecode-behind:

 From Page_Onload:

  if (Request.QueryString["pageid"] == null)                 {    // Eror handling here.                 }                 else                 {                     intPageID = int.Parse(Request.QueryString["pageid"]);                     PageData mypage = DataFactory.Instance.GetPage(new PageReference(intPageID));                     if (mypage == null)                     {    // Error handling here.                     }                     else                     {    // Setting up values for some  of the page                         tbMainBody.Text = mypage.Property["MainBody"].Value.ToString();                         tbMainIntro.Text = mypage.Property["MainIntro"].Value.ToString();                         tbWriterName.Text = mypage.Property["WriterName"].Value.ToString();                         tbName.Text = mypage.PageName;                         lblDocID.Text = mypage.PageLink.ID.ToString();                     }                 }


 And this is from the <asp:Button>'s 'OnClick' event handler:

                PageData mypage = DataFactory.Instance.GetPage(new PageReference(intPageID));                 if (mypage != null)                 {                     PageData writablepage = mypage.CreateWritableClone();                     string Name = tbName.Text.Length == 0? mypage.PageName : tbName.Text.Trim();                     string WriterName = tbWriterName.Text.Trim();                     string MainIntro = tbMainIntro.Text.Trim();                     string MainBody = tbMainBody.Text.Trim();                     writablepage.Property["WriterName"].Value = WriterName;                     writablepage.Property["MainIntro"].Value = MainIntro;                     writablepage.Property["MainBody"].Value = MainBody;                     writablepage.PageName = Name;                     PageReference prEditedPage = DataFactory.Instance.Save(writablepage, SaveAction.Publish);                     Response.Redirect(DataFactory.Instance.GetPage(prEditedPage).LinkURL);                 }                 else                 {    // Error handling here.                 }

 The idea were taken from this good example: http://labs.episerver.com/Blogs/Ted-Nyberg/Dates/112276/3/Modify-and-publish-a-page-programmatically/

 But... In my case the only one result I get - is the similar content for several varsions of the same page. Even if I change the content in text boxes - I keep getting the original one (i.e. the unchanged original content). What I'm doing wrong?

 

#19701
Apr 28, 2008 14:51
Vote:
 

Hi!

Have you debugged the code to see if the data has been populated for the text boxes and that the code actually does what you want it to do? Are versions created when you look in the regular EPiServer edit interface and does the changes get reflected when loading versions here?

#19703
Apr 28, 2008 15:04
Vote:
 

I solve the problem!

I got my brain shutted down when start writing the code-behind... I forgot "if (!Page.IsPostBack) { ... }" block in the Page_OnLoad() event handler - shame on me...

#19706
Apr 28, 2008 15:34
Vote:
 

The next problem - is to invoke the built-in editor. Can someone advise me about the typical way of invoking the <EPiServer.Property>'s editor? Setting 'EditMode' to 'true' don't do anything useful - I get the browser's error where I can see 'EPi.Dialog is null or not an object'.

So, I have an aspx-form, an EPiServer.Property on it and I'd like to 'force run' the build-in editor.

#19708
Apr 29, 2008 8:43
Vote:
 

Hi!

Check out the following thread, http://www.episerverworld.com/Forum/Pages/Thread.aspx?id=19369&epslanguage=en.

Linus wrote a reply about how that can be done in EPiServer CMS 5.

#19710
Apr 29, 2008 9:59
Vote:
 
Thank you, Per!
#19714
Apr 29, 2008 11:35
Vote:
 

I feel myself completely stupid...

I got editor running at last (thanks to the article written by Linus!) but now I cannot get changes back to be written to the DB :)

I got the <EPiServer:Property>-component - how can I simply get the edited value in the same way as it may be done with ordinary <asp:TextBox> by accessing its "Text" property (myWritablePage.Property["MainBody"].Value = tbMainBody.Text;)?

Let's suppose I have the property named "propMainBody".

Thank you in advance.

#19717
Apr 29, 2008 13:21
Vote:
 
No solution here?... :-(
#19729
Apr 30, 2008 12:05
Vote:
 

Hi again!

Unfortunately we do not have a property for the value of the inner property of the property web control but this is something that we will have in mind for future releases.

If you just want to update the current page properties you can call the method SavePage() that exists on EPiServer.PageBase. This methods requires a writable version of the current page and this has to be set up early in the page life cycle. We have example code for this for the start page of the workroom page in the demo templates where we solve this by override the CurrentPage property of the page and set it to a writable clone if required at the first request in the page.

Regards
Linus Ekström
EPiServer Development Team

#19731
Apr 30, 2008 12:57
Vote:
 

Greetings, Linus!

Let me explain what I'm trying to do so you can recommend me something.

I have a static aspx-form (created as EPiServer template) and I'm referencing it with direct call, not using any kind of content pages made "over" this template. I think this shouldn't be required for the simple service form. Inside Page_Load event handler I'm checking for the "pageid" query string parameter and if it isn't null - I'm loading the content page with this provided ID, using something like this:

  PageData mypage = DataFactory.Instance.GetPage(new PageReference(intPageID));

 

Next, I'm filling usual <asp:TextBox>-es with properties of this "mypage" instance. And, when stayng on this path - I got everything I need except for the lack of this good internal RichText Editor. The final strings from the event handler which is hooked to the <asp:Button> to confirm the edit process, looks like this:

PageReference prEditedPage = DataFactory.Instance.Save(writablepage, SaveAction.Publish); 
Response.Redirect(DataFactory.Instance.GetPage(prEditedPage).LinkURL);

 

As you understand from my eralier postings - I'd like to use something more intelligent than "dumb" TextBox for editing my content. So I've simply placed an <EPiServer:Property> on my page, set its PropertyName and PageLink values accroding to the original data which I'd like to edit:

propMainBody.PropertyName = "MainBody"; propMainBody.PageLink = mypage.PageLink; propMainBody.EditMode = true; propMainBody.DataBind();

 

And it works! I've got the editor, which allows me to edit everything. But I still don't understand how may I save changes. Because I'm working with "static" page - I think updating properties of the current page won't do anything usefull (I may be wrong of course, I don't know much about EPiServer developping yet).

PS: I'm sorry but we here in Moscow failed to get "public template" (and "demo template" too, of course) properly installed with EPiServer SDK... So we can only study code-behinds...

 PPS: Sorry for my poor (sometimes) English... Embarassed

Best regards,

Andrey

#19736
Edited, Apr 30, 2008 15:19
Vote:
 

If you just want to update the current page properties you can call the method SavePage() that exists on EPiServer.PageBase. This methods requires a writable version of the current page and this has to be set up early in the page life cycle. We have example code for this for the start page of the workroom page in the demo templates where we solve this by override the CurrentPage property of the page and set it to a writable clone if required at the first request in the page.

 I can't find the example code you're speaking about. Could you tell me a name of the file in which this sample may be located?

And I still don't have any success in my task... Cry

#19773
May 05, 2008 10:34
Vote:
 

Hi!

Here is some code that you can use to extract the value of your editor when using the property control. (Se the id of your property to "MainBodyProperty" in the code front)

PropertyData writableProperty = MainBodyProperty.InnerProperty.CreateWritableClone();
PropertyDataControl innerPropertyControl = MainBodyProperty.Controls[0] as PropertyDataControl;
innerPropertyControl.PropertyData = writableProperty;
innerPropertyControl.ApplyEditChanges();
object myValue = writableProperty.Value;

Regards
Linus Ekström

#19802
May 06, 2008 17:43
Vote:
 

Thank you, Linus!

I'll try your code as soon as possible.

#19808
May 07, 2008 8:56
Vote:
 

Hi Linus,

 Just tried your code and it worked perfectly!

 I wanted to let my users edit the MainBody property on a page. After authenticating the user and checking his rights I opened my page with the MainBody with EditMode = true;

codebehind:

PageData writeableClone = CurrentPage.CreateWritableClone();
            PropertyData writeableProperty = epMainBody.InnerProperty.CreateWritableClone();
            PropertyDataControl innerPropertyControl = episerverMainBody.Controls[0] as PropertyDataControl;
            if (innerPropertyControl != null)
            {
                innerPropertyControl.PropertyData = writeableProperty;
                innerPropertyControl.ApplyEditChanges();
                object myValue = writeableProperty.Value;

                writeableClone.Property["MainBody"].Value = myValue.ToString();
                DataFactory.Instance.Save(writeableClone, SaveAction.Publish);
                Response.Redirect(writeableClone.LinkURL);
            }

#23230
Sep 01, 2008 15:59
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.