R
Ranginald
Hi,
My goal is to have a class named class1 that will render a label
control on whatever page needs it. I want to instantiate class1 from
whatever page, and then call the createLabel() method defined in
class1.
My ultimate goal is to use this structure as a template for adding
dropdownlists (but I want to understand a simple example first).
In the following basic code, the code compiles but I cannot get the
label to display on the web page. I don't want to touch the design
view and I want to do it all in code.
Any suggestions are greatly appreciated.
---------------
class1.cs
----------------
namespace Lefantze
{
using...
public class Class1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label label1;
public Class1()
{
}
public void createLabel()
{
label1 = new Label();
label1.EnableViewState = true;
this.Controls.Add(label1); <-- I tried this
base.Controls.Add(label1); <-- I tried this
label1.Text = "This is from Class1, createLabel()";
}
}
}
--------------
default2.aspx.cs
--------------
using.....
using Lefantze;
public partial class Default2: Class1
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 rangy = new Class1();
rangy.createLabel();
}
}
Thanks!
My goal is to have a class named class1 that will render a label
control on whatever page needs it. I want to instantiate class1 from
whatever page, and then call the createLabel() method defined in
class1.
My ultimate goal is to use this structure as a template for adding
dropdownlists (but I want to understand a simple example first).
In the following basic code, the code compiles but I cannot get the
label to display on the web page. I don't want to touch the design
view and I want to do it all in code.
Any suggestions are greatly appreciated.
---------------
class1.cs
----------------
namespace Lefantze
{
using...
public class Class1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label label1;
public Class1()
{
}
public void createLabel()
{
label1 = new Label();
label1.EnableViewState = true;
this.Controls.Add(label1); <-- I tried this
base.Controls.Add(label1); <-- I tried this
label1.Text = "This is from Class1, createLabel()";
}
}
}
--------------
default2.aspx.cs
--------------
using.....
using Lefantze;
public partial class Default2: Class1
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 rangy = new Class1();
rangy.createLabel();
}
}
Thanks!