User control communication within Master page

R

robgallen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top