By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,709 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,709 IT Pros & Developers. It's quick & easy.

User control communication within Master page

P: n/a
I have 2 user controls within a master page, and I would like one of
them to call a function in the other.

All the examples I have seen involve a page communicating with the
Master page, or with a user control communicating with the Master
page, not with a user control directly talking to another user
control, bypassing the page itself.

So, I have the following files:
Haep.master - which contains:
Equip.ascx
Compare.ascx
(also there are 16 ASPX pages that inherit from the Master page)

To demonstrate I have tried my hardest to read this forum, here's what
I've got working so far. The aspx pages have a function in them to set
the public property of Equip.ascx. I am currently using

-- in *.aspx.cs:
((Haep)Page.Master).EquipXmlFile = "myfile";

-- in Haep.master.cs
public string EquipXmlFile
{
get { return ucEquip.XmlFile; }
set { ucEquip.XmlFile = value; }
}

and this works fine, passing the correct XmlFile parameter to the
Equip.ascx user control. I have not set the @MasterType, so I have had
to cast the Master page. However this still works well for this simple
function.

So, that's an example of what I have got working... now my problem is,
within Equip.ascx there is a function from which I would like to call
a different function in Compare.ascx. Neither of these user controls
are within the *.aspx pages, they are in the Haep.master page. I've
tried casting the Master page and also Compare.ascx from within
Equip.ascx.cs, but I still cannot get hold of the public function I
want.

Ideally I want something like this:
-- in Equip.ascx.cs
private void Something_Click(...)
{
UserControl ucCompare = (...properly casted Compare.ascx user
control...);
ucCompare.DoSomething(...);
}

-- in Compare.ascx
public void DoSomething(...)
{
// do something
}

Do I need to start looking at events instead, or is there an easy way
I can get the user controls to talk to each other, even if it is via
an intermediate public function within the Master page itself? Any
help would be much appreciated, this is driving me nuts.

Jul 18 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.