Changing Property values in EditPanel

 

Hi,
I want to change the values of page properties when an editor clicks on a button (custom property) on the Editpanel. The properties I want to change are just normal properties and not contained in this custom property. The values are retrieved from the metadata out of ImageVault, but that is not the real issue now.

I have tried several solutions but none give me the required result.

1.
I tried it with a clickEvent:

btnMeta.Text = "Retrieve Metadata";
btnMeta.Click += new EventHandler(btn_Click);


And the handler:

void btn_Click(object sender, EventArgs e) {
  PageData pd = EPiServer.DataFactory.Instance.GetPage(new PageReference(CurrentPage.PageLink.ID));
  IVMetadata meta = new IVMetadata();
  meta.GetMetadataById(pd);

  string descr = meta.duration1;

  PageBase oPage = (PageBase)this.Page;

  PageData pageStory = oPage.GetPage(new PageReference(CurrentPage.PageLink.ID));
  PageData y = pageStory.CreateWritableClone();

  ((PropertyLongString)y.Property["Caption"]).Value = descr;
  pageStory = y;

  DataFactory.Instance.Save(pageStory, EPiServer.DataAccess.SaveAction.Save, EPiServer.Security.AccessLevel.NoAccess);
  DataFactory.Instance.Save(pageStory, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
}

Now after the event has been executed and the page refreshes, the values are not shown. I have to refresh the page by clicking on the page in the left menu for the changes to be shown. Is there some sort of cache I need to flush for the changes to be visible straight away after the page refreshes normally?

I tried it with:

DataFactoryCache.RemovePage(CurrentPage.PageLink);
DataFactoryCache.RemoveListing(CurrentPage.PageLink);

But that does not work.

2.
I tried it by using a normal button that passes a variable through the url. So I get /EditPanel.aspx?id=[someid]&override=1

The button looks like this:

Meta.Text = "Retrieve Metadata";
Meta.PostBackUrl = "/admin/UI/edit/EditPanel.aspx?id=[someid]&override=1";


If the url contains the parameter "override" than I execute the following code:

string url = HttpContext.Current.Request.Url.Query.ToString();
if (url.EndsWith("override=1")) {
  PageData pd = EPiServer.DataFactory.Instance.GetPage(new PageReference(CurrentPage.PageLink.ID));
  IVMetadata meta = new IVMetadata();
  meta.GetMetadataById(pd);
  string descr = meta.duration1;
  CurrentPage.Property["Keyword"].Clear();
  CurrentPage.Property["Keyword"].Value = descr;
  CurrentPage.Property["Keyword"].ParseToSelf(descr);
  bool readonly = CurrentPage.Property["Keyword"].IsReadOnly;
}

This piece of code is indeed executed, but the value of the "Keyword" field is not changed (although I can see it changing in my VS debug screen). If I execute this code always (regardless of the fact if the user clicked on the button), then the value is changed. So this also could be caching.

I'm really stuck. Is there somebody who can help me with this?

Thanks for your time.

Gr,

Erol

 

 

#28979 Apr 01, 2009 12:06
  • Per Bjurström
    Member since: 1999
     

    Basically the editor is editing a version, so you can't do something in the background to the published version because it will not affect this version.

    Why not just make a plugin to EditPanel instead ?

    #28985 Apr 01, 2009 16:19
  •  

    ok, that would explain it.

    How would I go about creating such a plugin? Can you perhaps point me in the right direction? I thought using custom properties was the only way to go. Or do you mean a plugin that would be placed next to the "Edit", "View", "Versions" etc. tabs?

    Thanks.
    Erol

    #29053 Apr 02, 2009 17:55
  • Anders Hattestad
    Member since: 1996
     

    Hi

    If you make a plugin like I did in part 3 here:

    http://labs.episerver.com/en/Blogs/Anders-Hattestad/Dates/2009/2/PropertyDate-and-editores-in-different-TimeZone/

    then you could before you Populate the EditPanel find all the values and update them there. The only part you then need to resolve is to detect when you are going to do that :), I trick I use is to check if the button's name is inside Request[xxx] if it is, then your button  is pressed. that can be done before the button is added btw. You only need to know the name

    #29058 Apr 03, 2009 7:56
  •  

    Thanks, I'll try it out

     Gr,

    Erol

    #29070 Apr 03, 2009 12:49