C
Christian Döring
Hi,
Is it ok to create a new instance of a class on every Page_Load?
Given the following code behind a form:
protected void Page_Load(object sender, EventArgs e)
{
myclass= new MyClass(myControl);
}
protected void btnStart_Click(object sender, EventArgs e)
{
myclass.loadXYZ(0);
}
And the snippet from MyClass
public MyClass (MyControl c)
{
this.mycontrol = c;
}
public loadXYZ(int x)
{
...
c.text="abc"
}
So I need a reference to myControl which is on the form. My first approach
was to just pass it by the constructor of MyClass on the Page_Load event. Is
this just fine or do I loose performance?
Is it ok to create a new instance of a class on every Page_Load?
Given the following code behind a form:
protected void Page_Load(object sender, EventArgs e)
{
myclass= new MyClass(myControl);
}
protected void btnStart_Click(object sender, EventArgs e)
{
myclass.loadXYZ(0);
}
And the snippet from MyClass
public MyClass (MyControl c)
{
this.mycontrol = c;
}
public loadXYZ(int x)
{
...
c.text="abc"
}
So I need a reference to myControl which is on the form. My first approach
was to just pass it by the constructor of MyClass on the Page_Load event. Is
this just fine or do I loose performance?