473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Usercontrol not rendered in table

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)
Nov 19 '05 #1
1 1400
Anon wrote:
PictureBox)P

My guess is that you are ignoring the various stages of the life cycle of
controls. There is a time to build the controls, there is a time to
prerender controls, there is a time to render the controls.
As to the events, try catching the events by bubbling the events from the
image button.
I hope this helps

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anon | last post by:
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...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
4
by: sebastien | last post by:
Hi, In page_load : If Not Page.IsPostBack Then Dim myUC As UserControl = LoadControl("ficheProspects.ascx") myUC.ID = "FicheProspects1" End If In another Sub i need to find my control :
2
by: John Olsen | last post by:
Hi. I`m building a small CMS, and want to add the possibility to include server side code inside static html-strings that is stored in a database. For e.g. in the string...
3
by: Jeff Turner | last post by:
I want to install a few .NET assemblies on the local machine and then embed a UserControl in IE via COM -- in other words, I will wrap the assembly in COM and call it form IE so that my UserControl...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
1
by: SlimFlem | last post by:
I hope this makes sense. Here is what I am attempting. I have an inital generic aspx page that has one custom tag: <web:site id=webSite runat=server/> When this control evaluates, it will...
5
by: Tarun Mistry | last post by:
Hi all, is it possible to update a usercontrol before it is rendered? In my scenario I have a Page with a usercontrol on it. When a button is clicked on the Page, I want to update the...
0
by: Rob Blij | last post by:
Hi We have ported a .NET1.1 ASP.NET app to .NET2. All our user controls have been modified and I have found some strange behavior. Firstly I can see that the controls now get rendered at...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.