Creating your own Sitecore Fields can be tricky. The best way to start is to download one of Sitecores examples (the composite control is a good example).
In this example I’ll use the HandleMessage function in my control to open a modal window, do some stuff and return the values to my control.
The HandleMessage function reacts on events from the Sitecore Client. Each message contains the ID of the current control, which I will use to react to messages that belongs to me:
public override void HandleMessage(Sitecore.Web.UI.Sheer.Message message) { if (message["id"] == this.ID) { if ( message.Name == "MyControl:message" ) { System.Web.HttpContext.Current.Session["MyControl.ID"] = this.ID; ClientCommand command = Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog("MyPage.aspx", "300px", "630px", "my:Message", false); } } }
The trick is now that when the modal dialog closes, a message called “my:Message” will be thrown. Unfortunately there is no control ID attached to the message. In order to identify which control opened the modal window, I store the control’s ID in a session variable, and use this ID when handling the my:Message message:
if ( message.Name == "my:Message" ) { string id = System.Web.HttpContext.Current.Session["MyControl.ID"] as string; if (id == this.ID) { // do my work, and remember to clear the session } }
Pingback: Sitecore Custom Field – Image Coordinate Picker – Walking on clouds