ASCX controls

F

Fabrizio

Hi,
how is possible to manage a label or a text control created in a WEB USer
control from the page code?
I created a ascx control nested into a page. Loading the page i need to
change the value of one or more labels in the ascx control, with values that
the ascx doesn't have
Thank you,
Fabrizio
 
J

Joerg Jooss

Fabrizio said:
Hi,
how is possible to manage a label or a text control created in a WEB
USer control from the page code?
I created a ascx control nested into a page. Loading the page i need
to change the value of one or more labels in the ascx control, with
values that the ascx doesn't have


Expose the relevant properties of the individual user controls as properties
of your use control:

public class AddressControl : System.Web.UI.UserControl {
protected System.Web.UI.WebControls.TextBox firstNameTextBox;


private void Page_Load(object sender, System.EventArgs e) {
//...
}

public string FirstName {
get { return this.firstNameTextBox.Text; }

set { this.this.firstNameTextBox.Text = value; }
}
}

Cheers,
 
D

Das

Hi Fabrizio,
You can access the contol, if the object (lable in your case) as public
object. then set the values at run time.
For that within the main form you will have to declare an object with name
of the control object of the control type
for example:
My control is :
UserControlTest

When I place that control on the form I'll create the obejct named

protected UserControlTest userControTest1;


Now you can access the properties by 'userControTest1' object.

HTH,


Regards,
Das
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top