How do I put a user control into a table?

R

Robin Bonin

I have a user control that create a product thumbnail and details. I am
working on aother user control that I will pass some variables like # of
columns and rows to display these thumbnails. I'm having trouble dynamicly
adding a new thumbnail control to my table.

Dim newCell As New TableCell
Dim newRow As New TableRow
Dim productThumb As New htmlBlock_ProductThumb ' This is my
usercontrol

newCell.Controls.Add(productThumb) ' Not
sure how to add it to the table cell
newRow.Cells.Add(newCell)

FeaturedProducts.Rows.Add(newRow)
 
S

S. Justin Gengo

Robin,

When you load a user control it's slightly different than creating a dynamic
control.

newCell.Controls.Add(LoadControl([Path to your user control as String])

And you won't need to create the user control before this so delete the
line:

Dim productThumb As New htmlBlock_ProductThumb ' This is my usercontrol

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
R

Robin Bonin

Found the answer to my question.
for reference...

Dim newCell As New TableCell
Dim newRow As New TableRow
Dim productThumb As New Control

productThumb =
LoadControl("../userControls/htmlBlock_ProductThumb.ascx")
CType(productThumb, htmlBlock_ProductThumb).itemSku = "1001A"
newCell.Controls.Add(productThumb)

newRow.Cells.Add(newCell)
FeaturedProducts.Rows.Add(newRow)


Robin Bonin said:
This worked great, I just have one problem.
I need to pass atleast one paramater to this control for the item ID to be
dsiplayed.

I declared the control as follows.
productThumb = LoadControl("../userControls/htmlBlock_ProductThumb.ascx")

but the public properties are not exposed though the productThumb control. I
tried passing a variable
through the querry string but I got an error. control needs to end with a
.ascx.



S. Justin Gengo said:
Robin,

When you load a user control it's slightly different than creating a dynamic
control.

newCell.Controls.Add(LoadControl([Path to your user control as String])

And you won't need to create the user control before this so delete the
line:

Dim productThumb As New htmlBlock_ProductThumb ' This is my usercontrol

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Robin Bonin said:
I have a user control that create a product thumbnail and details. I am
working on aother user control that I will pass some variables like # of
columns and rows to display these thumbnails. I'm having trouble dynamicly
adding a new thumbnail control to my table.

Dim newCell As New TableCell
Dim newRow As New TableRow
Dim productThumb As New htmlBlock_ProductThumb ' This is my
usercontrol

newCell.Controls.Add(productThumb)
'
Not
sure how to add it to the table cell
newRow.Cells.Add(newCell)

FeaturedProducts.Rows.Add(newRow)
 

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

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top