Home All Groups Group Topic Archive Search About

Controls calling other controls problem - ASP.NET 2.0

Author
21 Sep 2006 10:35 AM
Griff
Hi

I have a web page (content.aspx) that inherits from a master page
(MasterPage.master).

The master page has a control (which has to be on every web page, hence on
the master page) (MasterControl.ascx).  When placed on the master page this
appears as <uc1:MasterControl ID="MasterControl1" runat="server" />.

The MasterControl's Page_Init() event will contain some code to examine the
Request object's properties (cookies) and calculate some value that it will
expose as a property.  This property is called "ImportantProperty()".

Content.aspx has a specific control on it (ContentControl.ascx).  When
placed on the web page this appears as
<uc1:ContentControl ID="ContentControl1" runat="server" />.

The problem...

The ContentControl.ascx's Page_Load() event must call the
"ImportantProperty()" in the MasterControl.  The resulting value dictates
which view (another user control) to dynamically load at run time
(View1.ascx, View2.ascx or View3.ascx).

MSDN gives an example of how to call a property on the MasterControl from
the Content.aspx page but NOT from a control on the Content.aspx page.
Microsoft's example can be found on:
http://msdn2.microsoft.com/en-us/library/c8y19k6h.aspx  I've tried to amend
their example without success....could someone put me out of my misery
please?

Many thanks

Griff

Author
21 Sep 2006 12:37 PM
Cowboy (Gregory A. Beamer)
Have the page call to each control. Ultimately, the architecture is such
that both the user control and the web control are controls on the page. The
control of painting is passed to the master page, which makes it appear
different, but it is, in essence a user control.

Your other option is to iterate through the page controls until you find the
master page, use reflection and set the property. I have not personally
tried this, but this is the only way I know of getting the property.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
Show quoteHide quote
"Griff" <howl***@the.moon> wrote in message
news:OrI8lmW3GHA.4764@TK2MSFTNGP02.phx.gbl...
> Hi
>
> I have a web page (content.aspx) that inherits from a master page
> (MasterPage.master).
>
> The master page has a control (which has to be on every web page, hence on
> the master page) (MasterControl.ascx).  When placed on the master page
> this appears as <uc1:MasterControl ID="MasterControl1" runat="server" />.
>
> The MasterControl's Page_Init() event will contain some code to examine
> the Request object's properties (cookies) and calculate some value that it
> will expose as a property.  This property is called "ImportantProperty()".
>
> Content.aspx has a specific control on it (ContentControl.ascx).  When
> placed on the web page this appears as
> <uc1:ContentControl ID="ContentControl1" runat="server" />.
>
> The problem...
>
> The ContentControl.ascx's Page_Load() event must call the
> "ImportantProperty()" in the MasterControl.  The resulting value dictates
> which view (another user control) to dynamically load at run time
> (View1.ascx, View2.ascx or View3.ascx).
>
> MSDN gives an example of how to call a property on the MasterControl from
> the Content.aspx page but NOT from a control on the Content.aspx page.
> Microsoft's example can be found on:
> http://msdn2.microsoft.com/en-us/library/c8y19k6h.aspx  I've tried to
> amend their example without success....could someone put me out of my
> misery please?
>
> Many thanks
>
> Griff
>
Author
21 Sep 2006 12:53 PM
Griff
Hi

Do you have any code example?  I'm just not sure how the Content Page's User
Control can access properties on the Master Page's User Control....

Thanks

Griff