HI ,
1.create Base usercontrol which contains a label and sets text of it to be "test1" this is set in the ascx page. 2.Create a user control which inherits from the base user control. 3. Now on the page load of the child control i try to do:
protected override void Page_Load(object sender, EventArgs e) { //Exception thrown by this as Label1 is null this.Label1.Text = "sasasas";
}
However i get an exception because the Label1 is null.
Can aonyone tell me how to initialize the base controls controls when the child control is created?????
thanks开发者_开发知识库 Niall
As RPM1984 commented: do not inherit from your Webusercontrol but nest it inside of your other Usercontrol. When you have exposed a Control(f.e. your Label or its Text property) as property in the "parent"-UC, you can access it from your "child"-UC.
Besides, always use LoadControl to initialize an dynamically added Usercontrol and not the constructor (what might be the cause that the Textbox is NULL).
精彩评论