On Sun, 17 Apr 2005 21:21:03 -0500, Patrick.O.Ige""
<Pa*********@discussions.microsoft.com> wrote:
I created a USERCONTROL and i want to call a LABEL from an ASPX page.
The USERCONTROL is in the ASPX page
I have the label :-
Label lblstr = new Label();
And displaying using:-
lblstrp.Text=lblstr.Text;
<asp:label id="lblstrp" BorderColor="#ff3333" BorderStyle="Dashed"
BorderWidth="3" ForeColor="#0033cc"
Font-Size="25" Runat="server" Width="55%"
BackColor="#ffff00"></asp:label>
I have a user control" header.ascx".
I want to place the usercontrol in the ASPX page using for example
<HEADER:topheader runat="server"></HEADER:topheader>
Any ideas?
I'm not sure I understand, your post is a little confusing. But to answer
the question posed in the subject, the usercontrol has a .Page property,
from which you can call FindControl to get the control by it's id (you'll
have to cast the result to a Label).
However, IMHO, this is not a good design. The usercontrol should not know
about controls in the page containing it, because that limits the
usefulness of the usercontrol as it can only be used in a page that has
the label. However, you could have your page inherit from a base class
that informs the usercontrol of the label (perhaps as a property). Of
course then your usercontrol still can only go inside these types of page.
Otherwise user controls should be black boxes that communicate and are
affected by its properties and events being set or handled by pages; the
page pulls or sets info on the usercontrol while also listening for events
from it...
just my opinion...
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET