468,278 Members | 1,571 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,278 developers. It's quick & easy.

WebUserControl

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[i] = new userctrl();
controls[i].Visible = true;
TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Controls.Add(controls[i]);
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
Nov 18 '05 #1
1 2275
Got that!
instead of writing
controls[i] = new userctrl();

write this
Control controls[i] = LoadControl("userctrl.ascx");
"Serdar Kalaycę" <se***********@unisec.com.tr> wrote in message
news:ue*************@TK2MSFTNGP12.phx.gbl...
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[i] = new userctrl();
controls[i].Visible = true;
TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Controls.Add(controls[i]);
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mike Levin | last post: by
2 posts views Thread by Arun | last post: by
1 post views Thread by DichkoSoft | last post: by
reply views Thread by Christian H | last post: by
2 posts views Thread by Oren | last post: by
2 posts views Thread by Oren | last post: by
reply views Thread by Giovanni | last post: by
reply views Thread by Klaus Jensen | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
1 post views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.