S
Sascha Ahmann
Hello,
i am experimenting with WebUserControls some
days now, and cant figure out what the easiest way
to change propertys at runtime with many WebUserControls
on one mainpage.aspx.
Background:
I have a mainpage.aspx, which queries a lot of databases. After
some validation it then loads a WebUserControl for each entry
in a table. The WebUserControl itself is a Table with many different
types of controls (labels, listboxes, dropdowns, textboxes, images
ect.).
Problem:
I dont want to create custom variables as public inside the WebUserControl
which are assigned to each control inside the WebUserControl on Page_Load();
Solution:
WebUserControl.ascx.cs (simplified example)
===============================
public class WebUserControl1 : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.Label Label1;
public System.Web.UI.WebControls.Table Table1;
private void Page_Load(object sender, System.EventArgs e)
{
} ........
===========================================
WebForm1.aspx.cs (simplified example)
===========================================
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
WebUserControl1 entry = new WebUserControl1();
entry.Table1.BackColor = Color.Aqua;
Page.Controls.Add(entry);
}
============================================
So i thought that i can just make the Table1 in the WebUserControl
public, and i can change its properties at runtime from the WebForm1.
But at entry.Table1.BackColor = Color.Aqua; it brings me an error
regarding that i have not made an instance from the object.
Can someone lead me to right direction ?
Kind regards,
Sascha
i am experimenting with WebUserControls some
days now, and cant figure out what the easiest way
to change propertys at runtime with many WebUserControls
on one mainpage.aspx.
Background:
I have a mainpage.aspx, which queries a lot of databases. After
some validation it then loads a WebUserControl for each entry
in a table. The WebUserControl itself is a Table with many different
types of controls (labels, listboxes, dropdowns, textboxes, images
ect.).
Problem:
I dont want to create custom variables as public inside the WebUserControl
which are assigned to each control inside the WebUserControl on Page_Load();
Solution:
WebUserControl.ascx.cs (simplified example)
===============================
public class WebUserControl1 : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.Label Label1;
public System.Web.UI.WebControls.Table Table1;
private void Page_Load(object sender, System.EventArgs e)
{
} ........
===========================================
WebForm1.aspx.cs (simplified example)
===========================================
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
WebUserControl1 entry = new WebUserControl1();
entry.Table1.BackColor = Color.Aqua;
Page.Controls.Add(entry);
}
============================================
So i thought that i can just make the Table1 in the WebUserControl
public, and i can change its properties at runtime from the WebForm1.
But at entry.Table1.BackColor = Color.Aqua; it brings me an error
regarding that i have not made an instance from the object.
Can someone lead me to right direction ?
Kind regards,
Sascha