Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   How to reference an object in a user control from its parent page (http://www.velocityreviews.com/forums/t79862-how-to-reference-an-object-in-a-user-control-from-its-parent-page.html)

moondaddy 06-07-2004 04:22 AM

How to reference an object in a user control from its parent page
 
I have a page which has a user control called CheckOutStatusBar and it lives
in a table call like this:

<%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
Src="Navigation/CheckoutStatusBar.ascx" %>
html.....
<td>
<uc1:checkoutstatusbar id="CheckoutStatusBar1"
runat="server"></uc1:checkoutstatusbar>
</td>



I need to change the formating of a link button in CheckoutStatusBar.ascx
from its parent page. How an I get a reference to it from the parent page?

Thanks.


--
moondaddy@nospam.com



Sergey Poberezovskiy 06-07-2004 04:55 AM

How to reference an object in a user control from its parent page
 
All you do is put a declaration into the page:

Protected WithEvents CheckoutStatusBar1
As "ProjectName"."UserControlClassName"

and then it becomes available to you in code.

hope this helps

>-----Original Message-----
>I have a page which has a user control called

CheckOutStatusBar and it lives
>in a table call like this:
>
><%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
>Src="Navigation/CheckoutStatusBar.ascx" %>
>html.....
><td>
> <uc1:checkoutstatusbar id="CheckoutStatusBar1"
>runat="server"></uc1:checkoutstatusbar>
></td>
>
>
>
>I need to change the formating of a link button in

CheckoutStatusBar.ascx
>from its parent page. How an I get a reference to it

from the parent page?
>
>Thanks.
>
>
>--
>moondaddy@nospam.com
>
>
>.
>


Natty Gur 06-07-2004 04:57 AM

Re: How to reference an object in a user control from its parent page
 
Hi,

CheckoutStatusBar oCheckoutStatusBar1 =
FindControl("CheckoutStatusBar1");

but you need to expose public or internal function from your user
control that will handle link formating change.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

moondaddy 06-07-2004 05:47 AM

Re: How to reference an object in a user control from its parent page
 
Thanks that was perfect.

--
moondaddy@nospam.com
"Sergey Poberezovskiy" <anonymous@discussions.microsoft.com> wrote in
message news:18f1001c44c4b$a2213540$a501280a@phx.gbl...
> All you do is put a declaration into the page:
>
> Protected WithEvents CheckoutStatusBar1
> As "ProjectName"."UserControlClassName"
>
> and then it becomes available to you in code.
>
> hope this helps
>
> >-----Original Message-----
> >I have a page which has a user control called

> CheckOutStatusBar and it lives
> >in a table call like this:
> >
> ><%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
> >Src="Navigation/CheckoutStatusBar.ascx" %>
> >html.....
> ><td>
> > <uc1:checkoutstatusbar id="CheckoutStatusBar1"
> >runat="server"></uc1:checkoutstatusbar>
> ></td>
> >
> >
> >
> >I need to change the formating of a link button in

> CheckoutStatusBar.ascx
> >from its parent page. How an I get a reference to it

> from the parent page?
> >
> >Thanks.
> >
> >
> >--
> >moondaddy@nospam.com
> >
> >
> >.
> >




John Saunders 06-07-2004 11:46 AM

Re: How to reference an object in a user control from its parent page
 
"moondaddy" <moondaddy@nospam.com> wrote in message
news:uLP9mZETEHA.1732@TK2MSFTNGP09.phx.gbl...
> I have a page which has a user control called CheckOutStatusBar and it

lives
> in a table call like this:
>
> <%@ Register TagPrefix="uc1" TagName="CheckoutStatusBar"
> Src="Navigation/CheckoutStatusBar.ascx" %>
> html.....
> <td>
> <uc1:checkoutstatusbar id="CheckoutStatusBar1"
> runat="server"></uc1:checkoutstatusbar>
> </td>
>
>
>
> I need to change the formating of a link button in CheckoutStatusBar.ascx
> from its parent page. How an I get a reference to it from the parent

page?

It's best if you treat user controls like class instances (which they are).
This means that a user control shouldn't be exposing its link buttons to
the outside world. Instead, the user control should expose a method or
property which allows the link button formatting to change. For instance, in
the user control:

private bool _linkUnderlined = true;
public bool LinkUnderlined
{
get {return _linkUnderlined;}
set
{
_linkUnderlined = value;
if (_linkUnderlined)
{
lnkLinkButton.Styles["text-decoration"] = "underlined";
}
else
{
lnkLinkButton.Styles["text-decoration"] = "none";
}
}
}
--
John Saunders
johnwsaundersiii at hotmail




All times are GMT. The time now is 05:44 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.