tags:

views:

96

answers:

1

I have a page with 2 web controls that intentionally have no knowledge of each other. Each control also has its own helper class to take care of events and such. Only 1 of the controls (EditBox) has a "save" button on it and when it saves, it needs to grab data from the other control (MceEditorAlpha) on the page, how do I do this? The MceEditorAlpha control has SaveMessage() on it which will retrieve data from the EditBox control and save it in its helper class object, however, I don't know how to call SaveMessage() from the helper class.

Here is the control that does not have a save button on it.

    public partial class MceEditorAlpha : System.Web.UI.UserControl
    {
      public MceEditor Mce { get; set; }

      public void SaveMessage()
      {
          if (Mce == null)
              Mce = new MceEditor();
          Mce.Text = tbDescription.Text;
      }
    }

Now, in the helper class for MceEditorAlpha I have an event handler that fires when the "save" button on the EditBox control is pressed. What I need to do is get this event to trigger SaveMessage() in the class listed above. Do I have to create an event in MceEditor and a handler in MceEditorAlpha above?

    public class MceEditor : IMessageBroadcaster
    {
      public string Text { get; set; }

      public void OnEditBoxSave(object sender, EventArgs e)
      {
          //Handle the event from the EditBoxSave "save" button_click
      }
    }
+1  A: 

Well as i see it MceEditorAlpha has a referrence to MceEditor. To be able to recieve notifications from it make MceEditor expose a OnSave event and subsribe to it from MceEditorAlpha

AZ
Sounds good, I'm working on that now. I guess I've never really made and event handler that simply fires another event before.
kd7iwp