Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Communication between dynamically added custom user controls

Communication between dynamically added custom user controls

Scheduled Pinned Locked Moved ASP.NET
csharpwinformscomtutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adam Wimsatt
    wrote on last edited by
    #1

    I'm using Sitefinity (www.sitefinity.com) and trying to get two custom built controls to talk to each other. I'm looking for suggestions as to how I could accomplish this. I'm using .Net 3.5. Right now I can pass data one way using the Page.Context.Items collection and viewing that from the OnPreRender(). One control is a breadcrumb generator and the other is a browse control. The two should work in tandem. When the breadcrumb trail is clicked the navigation should update with that level's sub-items. And if a sub-item is clicked in the navigation control the breadcrumb should update accordingly (standard breadcrumb + navigation setup going against a heirarchical table) These controls are added to the page from the sitefinity interface, so I don't know what the ID or ClientID of these controls will be as it is controlled by the sitefinity CMS software. I do have access to the Page object inside each control. I would love to use Events to communicate between the two, I'm just not sure how to make that happen or where in the page / control lifecycle to do it. Any suggestions?

    Fuzzy Llama Creative Solutions, Inc. Wordles LLC Pachuko Boy

    A 1 Reply Last reply
    0
    • A Adam Wimsatt

      I'm using Sitefinity (www.sitefinity.com) and trying to get two custom built controls to talk to each other. I'm looking for suggestions as to how I could accomplish this. I'm using .Net 3.5. Right now I can pass data one way using the Page.Context.Items collection and viewing that from the OnPreRender(). One control is a breadcrumb generator and the other is a browse control. The two should work in tandem. When the breadcrumb trail is clicked the navigation should update with that level's sub-items. And if a sub-item is clicked in the navigation control the breadcrumb should update accordingly (standard breadcrumb + navigation setup going against a heirarchical table) These controls are added to the page from the sitefinity interface, so I don't know what the ID or ClientID of these controls will be as it is controlled by the sitefinity CMS software. I do have access to the Page object inside each control. I would love to use Events to communicate between the two, I'm just not sure how to make that happen or where in the page / control lifecycle to do it. Any suggestions?

      Fuzzy Llama Creative Solutions, Inc. Wordles LLC Pachuko Boy

      A Offline
      A Offline
      Andreas X
      wrote on last edited by
      #2

      Hi! I made a test on the issue. Check my code snippets: EventInterface:

      public delegate void ControlChangedDelegate(ControlChangedEventArgs e);

      public class ControlChangedEventArgs : EventArgs
      {
      private object controlInfo;
      public object ControlInfo
      {
      get { return controlInfo; }
      set { controlInfo = value; }
      }

      public ControlChangedEventArgs(object info)
      {
          controlInfo = info;
      }
      

      }

      /// /// Summary description for EventInterface
      ///
      public interface EventInterface
      {
      event ControlChangedDelegate ControlChanged;

      void Updatecontrol(object info);
      

      }

      The page:

      public partial class _Default : System.Web.UI.Page, EventInterface
      {
      protected void Page_Load(object sender, EventArgs e)
      {

      }
      
      #region EventInterface Members
      
      public event ControlChangedDelegate ControlChanged;
      
      public void Updatecontrol(object info)
      {
          ControlChanged(new ControlChangedEventArgs(info));
      }
      
      #endregion
      

      }

      Control 1:

      public partial class WebUserControl : System.Web.UI.UserControl
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      ((EventInterface)this.Parent.Page).ControlChanged += new ControlChangedDelegate(WebUserControl_ControlChanged);
      }

      void WebUserControl\_ControlChanged(ControlChangedEventArgs e)
      {
          string s = e.ControlInfo.ToString();
          // do th cool things
      }
      

      }

      Control 2:

      public partial class WebUserControl2 : System.Web.UI.UserControl
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      string controlInfo = this.ID;
      ((EventInterface)this.Parent.Page).ControlChanged += new ControlChangedDelegate(WebUserControl_ControlChanged);

          ((EventInterface)this.Parent.Page).Updatecontrol(controlInfo);
          
      }
      
      void WebUserControl\_ControlChanged(ControlChangedEventArgs e)
      {
          string s = e.ControlInfo.ToString();
          // do the cool things
      
      }
      

      }

      i have not made any extensive test on this but i think it will work.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups