English 中文(简体)
How do I hook the Save event in Sitecore Page Editor?
原标题:

I m creating a custom edit control for my content authors to use in the Page Editor. Of course this means I want my control to save data to an Item when the user clicks on the Save button.

How is this done? I ve looked through many reams of documentation... feel like I m missing something basic. Surely I can add my own event handler here?

NOTE: I want this to be INLINE editing in the Page Editor. It seems like a very basic feature that is missing from Sitecore. I could certainly see using a checkbox entry also for a checkbox field (What a crazy notion?!?!). The only built-in options for editing seem to be a textbox or a RichText editor. Am I missing something obvious?

最佳回答

OK... after some help from Sitecore support, I ve finally got the answer to this question. In order for Page Editor to get new values for fields, the Sitecore.WebEdit.setFieldValue() javascript function needs to called. This creates a hidden input field which the PageEditor then reads when the Save or Save/Close button is clicked.

//RenderItem is the item in question, DropListField is the string name of
//the target Droplist field we want rendered
string itemID = RenderItem.ID.ToShortID().ToString();
string fieldID = RenderItem.Fields[DropListField].ID.ToShortID().ToString();
string language = RenderItem.Language.ToString();
string version = RenderItem.Version.ToString();
string revision = RenderItem[FieldIDs.Revision].Replace("-", string.Empty);

ddlList.Attributes.Add("onchange", string.Format("var ddl = getElementById( {5} );var itemURI = new Sitecore.ItemUri( {0} , {1} , {2} , {3} );Sitecore.WebEdit.setFieldValue(itemURI, {4} ,ddl.options[ddl.selectedIndex].value);",itemID,language,version,revision,fieldID,ddlList.ClientID));

So, basically we just add a client-side onchange handler for the DropDownList which calls this Sitecore js function. Note: I believe this requires Sitecore 6.2.

问题回答

When I need to build a custom control, I use it in Normal mode and then just use an sc:Text (or whatever) while the user is in Edit mode. That way I get all the Sitecore goodness without the hassle. One way to do this is to use a Multiview which looks kinda like:

<MultiView>
  <View id=NormalView>
    <MyAwesomeCustomControl />
  </View>
  <View id=EditView>
    <sc:Text />
  </View>
</MultiView>

Then in the code-behind make sure that you choose the right view for the right mode.

You could also use the field editor to bring up a popup to edit the info you need. Let s say for instance you do:

<sc:EditFrame runat="server" Buttons="MyThing">
<!-- any html, or other controls -->
</sc:EditFrame>

So when somebody in PageEditor (Edit) mode hovers over the html you put inside the EditFrame they will get a pop up menu. In this menu you can display any number of commands, the normal one would be an "Edit" option that then pops up a dialog, where you can edit any fields you want from any content Item in the tree.

How you configure the available options? Through the Buttons property, it has to point to a folder in the core database under the /sitecore/content/Applications/WebEdit/Edit Frame Buttons (see the default one as an example). It is also in there that you can set which fields to edit. In the snippet above, Sitecore expects to find a folder called MyThing.

How does it know which item to edit fields from? If you don t specify anything it will be the Context.Item, if you want something else, use the datasource property of the editFrame control and set it to for example some ID.





相关问题
How do I hook the Save event in Sitecore Page Editor?

I m creating a custom edit control for my content authors to use in the Page Editor. Of course this means I want my control to save data to an Item when the user clicks on the Save button. How is ...

Passing Parameters to a Sitecore Sublayout

I ve done this before with a web control, but I can t seem to get it to work with a sublayout. On the Presentation Details for a particular item I m assigning my Sublayout and then in the additional ...

Lucene.Net Search List

I m using Sitecore and have a multilist field I d like to use Lucene to search on. The problem I have is that the field is a pipe-delimited list of actual values and there could be between 0 and an ...

Test for Descendant Items

I am trying to create a simple inventory of items in a Sitecore website using an xslt. The problem is that I can t find a way to test whether an item has descendant items beneath it. It s easy to ...

Sitecore set/change default language from en

Can anyone recommend the best way to change the default language in Sitecore 6.1. On a fresh install, the typical language for all items is en English, witha nice little USA flag and all. However, ...

热门标签