By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,468 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,468 IT Pros & Developers. It's quick & easy.

How to add web user control to cell

P: n/a
Hi

Using C# in vs2003 to develop web stuff.

I created a "Web user control" (.ascx and ascx.cs files), that
contains a few simple (for starters) html items. I can place the item
on webform at development time and it works ok. What I want to do
however is be able to create an instance of a control and then add it
into the cell of a table row at run time. I cant seem to get this to
work. The Controls.Add method of the table cell requries a
System.Web.UI.Control object, but the user control I made is a
System.Web.UI.UserControl. Don't know if this is the problem or not.

This compiles and runs, but nothing shows up in the browser. Checking
the html sent to the browser, shows that there is nothing between the
<td id="cell_0_0" ></tdtags.

Here is a bit of what I was trying:

//Declare new instance of my user object
protected MyNamespace.header objHead;

//Get a reference to the table cell
System.Web.UI.WebControls.TableCell c =
(TableCell)Page.FindControl("cell_0_0");

//Create new instance of my object
MyNamespace.header objHead = new MyNamespace.header();

//Add the new object to the table cell
c.Controls.Add(objHead);
Thanks in advance
Jeff
Feb 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
instead of creating the control like such, try loading it like this:

objHead = (header )Page.LoadControl
("/UserControls/objHead.ascx");
this.Controls.Add(objHead);

replacing the folder userControls with what ever folder your ascx resides in.
Feb 5 '07 #2

P: n/a

Changing :
this.Controls.Add(objHead);
to this:
c.Controls.Add(objHead);

puts it in the cell exactly the way I want it!!

Thanks
Jeff
On Sun, 4 Feb 2007 21:26:00 -0800, XOR <XO*@discussions.microsoft.com>
wrote:
>instead of creating the control like such, try loading it like this:

objHead = (header )Page.LoadControl
("/UserControls/objHead.ascx");
this.Controls.Add(objHead);

replacing the folder userControls with what ever folder your ascx resides in.
Feb 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.