WebUserControls in VS2003

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
 

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top