WebUserControl

S

Serdar Kalaycý

Hi There,

I have a webusercontrol and it works allright when created at design time.
But when I try to create it at the runtime (this is because the number of
control needed is variable) I could not make them visible.

I put a line at the definitions like this,

protected userctrl[] controls;

and in Page_Load method

int count = 3;

controls = new userctrl[count];
for (int i=0; i<count; i++)
{
controls = new userctrl();
controls.Visible = true;
TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Controls.Add(controls);
td.Controls.Add(lbl);
tr.Cells.Add(td);
Table1.Rows.Add(tr);
}

And one more thing that made me confused. In some article I read on the Net
tells that when I drag&drop the ascx file on to the web form it puts the
control on the form (which is correct) and it adds this line to the code
protected userctrl userctrl1;
which is not happening for me, it just adds a line to the html code of the
page, nothing on the code behind...
I tried both selecting and deselecting "Run As Server Control" checkbox of
the user control...
What am I missing?
Thanks in advance
Serdar KALAYCI
 
S

Serdar Kalaycý

Got that!
instead of writing
controls = new userctrl();

write this
Control controls = LoadControl("userctrl.ascx");
 

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

Top