Usercontrol not rendered in table

G

Guest

I am programmatically populating a asp.net table control with my usercontrol
(PictureBox.ascx) which is basically an assortment of an imagebutton, Label
and a Linkbutton. Now while debugging the application i can see that the
control is being initialized properly (by setting the imgurl and text values
from the db), but for some reason the usercontrol does not show up in the
table.

Here is the code for the Page: (test.aspx)


//I am calling the ArrangePictures() function on the click event of a button
which basically starts to load a list of usercontrols

/////////////////////////////////////////////////////////////////////
private void ArrangePictures()
{
ArrayList Pics = LoadPictures();
TableRow r = new TableRow();
TableCell c;
foreach (object P in Pics)
{
c = new TableCell();
//this is where i am adding the control
//it does not throw any errors but instead
//spits out an empty cell
c.Controls.Add(((PictureBox)P));
r.Cells.Add(c);
if (r.Cells.Count == 3)
{
tblPictures.Rows.Add(r);
r = new TableRow();
}//if - Pics
}//foreach

if (r.Cells.Count == 2)
{
c = new TableCell();
c.ColumnSpan = 2;
r.Cells.Add(c);
tblPictures.Rows.Add(r);
}
else
{
c = new TableCell();
c.ColumnSpan = 2;
r.Cells.Add(c);
tblPictures.Rows.Add(r);
}

}//Arrange picture
////////////////////////////////////////////////////////////////////////////////////
private ArrayList LoadPictures()
{
OleDbDataReader rdrImages = getPictureData();
ArrayList Pictures = new ArrayList();
PictureBox Picture;
if (rdrImages.Read())
{//Skip first file - will be used in header
while (rdrImages.Read())
{
Picture = new PictureBox();
Picture.Picture.ImageUrl = Convert.ToString(rdrImages.GetValue(2));
Picture.Picture.AlternateText = Convert.ToString(rdrImages.GetValue(1));
Picture.TextCaption.Text = Convert.ToString(rdrImages.GetValue(1));
Pictures.Add(Picture);
}//while
}//if

if ((Pictures.Count < 9) && (Session["UserId"] == Session["ID"]))
{//add upload picture control if user is logged into their account
Picture = new PictureBox();
Picture.TextCaption.Text = "Add a new picture.";
Picture.Picture.ImageUrl = Request.ApplicationPath + "/images/add.jpg";
Picture.Picture.AlternateText = "Add a new picture.";
Pictures.Add(Picture);
}//if
return Pictures;

}//LoadPictures


Code for the user Control (PictureBox.ascx):
private ImageButton _Picture;
private Label _Caption;

public ImageButton Picture
{
get
{
_Picture.Height = Unit.Pixel(80);
_Picture.Width = Unit.Pixel(80);
return _Picture;
}
set { _Picture = value; }
}

public Label TextCaption
{
get { return _Caption; }
set { _Caption = value; }
}
public PictureBox()
{
this.TextCaption = new Label();
this.Picture = new ImageButton();
}

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
lblCaption = this.TextCaption;
ibtnPicture = this.Picture;
}


Also, how would i be able to add onclick events for these dynamically loaded
controls. (ex. for ImageButton)
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top