By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

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

P: n/a
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...
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <mi**********@hotmail.com> wrote in message
news:dd**************************@posting.google.c om...
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...

Nov 18 '05 #2

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

THANKS AGAIN!!!!
"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message news:<uO**************@TK2MSFTNGP12.phx.gbl>...
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" <mi**********@hotmail.com> wrote in message
news:dd**************************@posting.google.c om...
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...

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.