|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
User ControlsI declare a UserControl called header and in that header I declare a
<asp:label id=name> control. I reference this user control at the top of my HTML page. In my Page_load subroutine, I try to programatically set that "name" equal to something. I get an error saying that the "name" has not been defined. My guess is that the page_load routine is being run before the UserControl is referenced within the page. Is there a way that I can do this without getting the error? You need to create a Name property on your custom control that exposes the
label name... public readonly Label Name { get { return this.name } } Fred Show quoteHide quote "Paul" <P***@discussions.microsoft.com> wrote in message news:8A5E95B1-E263-4727-A657-0FDB37A4A938@microsoft.com... >I declare a UserControl called header and in that header I declare a > <asp:label id=name> control. I reference this user control at the top of > my > HTML page. > > In my Page_load subroutine, I try to programatically set that "name" equal > to something. > > I get an error saying that the "name" has not been defined. > > My guess is that the page_load routine is being run before the UserControl > is referenced within the page. > > Is there a way that I can do this without getting the error? Hi Paul,
A UserControl will be a different class then the main page it's used on and when you add a control to a user control it will usually have a protected access level. In the user control add a property in the code-behind to expose this property: protected Label name; .... public string LabelText { get { return name.Text; } set { name.Text = value; } } And then you can reference the property: <uc1:SampleUserControl LabelText="Here's some text" /> Cheers, Steve Goodyear
HELP!! Dynamically created webcontrol not accessible on postback
Looking for an Autocomplete DropDownList Datagrid ... is this the control from hell? What is .Net equivilent of Fieldset/Legend Datalist layout Best free/cheap Menu Control for 1.1 Staggering Data using DataList, Repeater, etc... Repeater and RadioButton DropDownlist and sorting Loading html file into panel |
|||||||||||||||||||||||