Communication between dynamically added custom user controls
-
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
-
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
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.