PLACEHOLDER NOT RENDERING CONTROLS... PLS HELP :-(

M

Mike Speak

I have a user control that I want to use to render 4 menu items
(retrieved from db) on the top of each of my asp.net pages.

The user control defines a table, with one TR and one TD. Within the
TD I have a placeholder defined:

<asp:placeHolder ID="categoriesPlaceHolder" Runat="server" />

In the code behind of the user control, on the Page_Load event I am
retrieving data from db and adding controls to the placeholder as
follows:

public class CategoryHeader : System.Web.UI.UserControl
{
protected PlaceHolder categoriesPlaceHolder;

private void Page_Load(object sender, System.EventArgs e)
{
string categoryName = "";
string categoryId = "";
LinkButton categoryItem;

categoriesPlaceHolder = new PlaceHolder();

// DB STUFF HERE

while (myDataReader.Read())
{
// PICK OUT DATA
categoryName = myDataReader["category"].ToString();
categoryId = myDataReader["id"].ToString();

// CREATE A NEW SERVER SIDE LINKBUTTON CONTROL
categoryItem = new LinkButton();
categoryItem.Text = categoryName;
categoryItem.ID = categoryId;
categoryItem.CommandArgument = categoryId;
categoryItem.CommandName = "CategoryLink_Click";

// ADD THE CONTROL TO THE PLACEHOLDER
categoriesPlaceHolder.Controls.Add(categoryItem);
}
}
}

While the rest of the user control is rendering correctly, the
LinkButtons within the placeholder are not rendering at all, there is
nothing within the user control TD where i want the menu items to
appear.

Any expert advice would be greatly appreciated...

TIA
mike...
 
C

Chris Jackson

You aren't adding controls to the placeholder you define on your page, you
are adding them to a new local PlaceHolder object, which is private and
never gets rendered. Take out the line where you instantiate a new
PlaceHolder, and things should work fine.
 
M

Mike Speak

Chris Jackson... thank you sooo much. I must have spent hours racking
my brain but you spotted it in one...

THANKS AGAIN!!!!


Chris Jackson said:
You aren't adding controls to the placeholder you define on your page, you
are adding them to a new local PlaceHolder object, which is private and
never gets rendered. Take out the line where you instantiate a new
PlaceHolder, and things should work fine.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

Mike Speak said:
I have a user control that I want to use to render 4 menu items
(retrieved from db) on the top of each of my asp.net pages.

The user control defines a table, with one TR and one TD. Within the
TD I have a placeholder defined:

<asp:placeHolder ID="categoriesPlaceHolder" Runat="server" />

In the code behind of the user control, on the Page_Load event I am
retrieving data from db and adding controls to the placeholder as
follows:

public class CategoryHeader : System.Web.UI.UserControl
{
protected PlaceHolder categoriesPlaceHolder;

private void Page_Load(object sender, System.EventArgs e)
{
string categoryName = "";
string categoryId = "";
LinkButton categoryItem;

categoriesPlaceHolder = new PlaceHolder();

// DB STUFF HERE

while (myDataReader.Read())
{
// PICK OUT DATA
categoryName = myDataReader["category"].ToString();
categoryId = myDataReader["id"].ToString();

// CREATE A NEW SERVER SIDE LINKBUTTON CONTROL
categoryItem = new LinkButton();
categoryItem.Text = categoryName;
categoryItem.ID = categoryId;
categoryItem.CommandArgument = categoryId;
categoryItem.CommandName = "CategoryLink_Click";

// ADD THE CONTROL TO THE PLACEHOLDER
categoriesPlaceHolder.Controls.Add(categoryItem);
}
}
}

While the rest of the user control is rendering correctly, the
LinkButtons within the placeholder are not rendering at all, there is
nothing within the user control TD where i want the menu items to
appear.

Any expert advice would be greatly appreciated...

TIA
mike...
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top