Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Modify User control at Hosting Page Page_Load Event


Message #1 by "Kan Yu Ting" <yu-ting.kan@p...> on Mon, 24 Jun 2002 10:28:30
Hi,

I have a page with several user control. One of the user control has a 
Label. How can I set the text value of this label in Hosting page's 
Page_Load event?

Thanks for help

Kan
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 24 Jun 2002 08:36:13 -0400
Kan,

	The easiest method of doing this is probably to make the label,
which is on the UserControl, public scope instead of protected.  When its
public you'll be able to do something like UserControl1.LabelName.Text 
"value".  However, to better encapsulate it (assuming the end user doesn't
need control over every aspect of the label), you should give your
UserControl a public property that is tied directly to the label's .Text
property.  This will retain look and feel of the UserControl while still
allowing the end developer to set the text to whatever they wish.

In UserControl:
---
protected Label title;

public string Title
{
	get { return title.Text; }
	set { title.Text = value; }
}
---
In consuming page:
---
protected UserControl uc;
private void Page_Load(...)
{
	uc.Title = "Your text here!";
}
---

HTH,
- Chuck

-----Original Message-----
From: Kan Yu Ting [mailto:yu-ting.kan@p...]
Sent: Monday, June 24, 2002 6:29 AM
To: ASP+
Subject: [aspx] Modify User control at Hosting Page Page_Load Event


Hi,

I have a page with several user control. One of the user control has a 
Label. How can I set the text value of this label in Hosting page's 
Page_Load event?

Thanks for help

Kan

  Return to Index