473,830 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usercontrol not rendered in table

I am programmaticall y populating a asp.net table control with my usercontrol
(PictureBox.asc x) 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.Row s.Add(r);

r = new TableRow();

}//if - Pics

}//foreach

if (r.Cells.Count == 2)

{

c = new TableCell();

c.ColumnSpan = 2;

r.Cells.Add(c);

tblPictures.Row s.Add(r);

}

else

{

c = new TableCell();

c.ColumnSpan = 2;

r.Cells.Add(c);

tblPictures.Row s.Add(r);

}

}//Arrange pictures

////////////////////////////////////////////////////////////////////////////////////

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.ToStrin g(rdrImages.Get Value(2));

Picture.Picture .AlternateText = Convert.ToStrin g(rdrImages.Get Value(1));

Picture.TextCap tion.Text = Convert.ToStrin g(rdrImages.Get Value(1));

Pictures.Add(Pi cture);

}//while

}//if

if ((Pictures.Coun t < 9) && (Session["UserId"] == Session["ID"]))

{//add upload picture control if user is logged into their account

Picture = new PictureBox();

Picture.TextCap tion.Text = "Add a new picture.";

Picture.Picture .ImageUrl = Request.Applica tionPath + "/images/add.jpg";

Picture.Picture .AlternateText = "Add a new picture.";

Pictures.Add(Pi cture);

}//if

return Pictures;

}//LoadPictures


Code for the user Control (PictureBox.asc x):
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.TextCaptio n = new Label();

this.Picture = new ImageButton();

}

private void Page_Load(objec t sender, System.EventArg s e)

{

// Put user code to initialize the page here

lblCaption = this.TextCaptio n;

ibtnPicture = this.Picture;

}


Also, how would i be able to add onclick events for these dynamically loaded
controls. (ex. for ImageButton)
Nov 22 '05 #1
0 883

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

Similar topics

0
931
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 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)
4
3123
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 UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
4
3356
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
3702
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 "<div><b>News></b><br></div>", should be replaced by the rendered html-outpu from a usercontrol that prints out database content. I use regex to get the content of the -tags, and load the control and get the output-html with the following code:
3
1706
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 (that is installed locally) shows up on a web page. Has anyone done anything like this before? I can't imagine this isn't possible. Basically I want to leverage a .NET assembly installed on the local machine from inside the browser (with...
1
6876
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 and page loading/rendering lifecycle.... Ok, now for the question: I have an ASPX page (page.aspx), and I have a UserControl (control.ascx). The UserControl has one textbox on the control, and one button control. I have added a public property...
1
1130
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 return a small amount of Html with another custom control tag inside this html. For example:
5
1297
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 usercontrol, more specifically making a placeholder become visible. However it wont work. Im confused. I catch the button click even on the page and within this i run a method on my usercontrol, however it doesnt seem to work. Few code lines given below. ...
0
1058
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 compile time instead of declaring them in the ascx.cs file. Then strange thing is: in our aspx page when we call Page.LoadControl(usercontrol) all the controls within the usercontrol dont get their unique ID ie ctl1_btnDetails etc except each...
6
12147
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 binding like normal. The problem I am running into is that my UserControl ends up with a different BindingContext then the ParentForm it is contained in and thus all other controls on the parent form. (I want various controls on the form to...
0
9781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10769
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10477
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10197
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.