tags:

views:

120

answers:

2

I have a master page and content placeholder. In contentplaceholder there is a place holder for that place holder I insert a dynamic linkbutton. When i run a page link button does not show up on the page.

for (int i = 0; i < UserCredentialsDT.Rows.Count; i++)
{
    switch (Convert.ToInt32(UserCredentialsDT.Rows[i]["RoleId"]))
    {
        case (int)Helper.UserRole.Administrator:
            Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
            LinkButton lnkAdmin = new LinkButton();
            lnkAdmin.Text = "Admin";
            lnkAdmin.ID = "lnkAdmin" + i.ToString();
            PlaceHolder1.Controls.AddAt(PlaceHolder1.Controls.Count, lnkAdmin);
            lnkAdmin.Visible = true;
            lnkAdmin.PostBackUrl = PresentationConstant.ASPX_ADMINSETTINGS;
            break;
     }
 }
+2  A: 

If you're dynamically adding this you'll probably want to be sure of which stage of page cycle you want to use. This may vary on other factors too. But certainly read up on your PreInit, Init and Load events.

dove
+2  A: 

This cannot be done inside the MasterPages ContentPlaceHolder, the ContentPlaceHolder is for WebForms that use the MasterPage. I would recommend putting your PlaceHolder control outside of the ContentPlaceHolder.

From MSDN:

A ContentPlaceHolder control defines a relative region for content in a master page, and renders all text, markup, and server controls from a related Content control found in a content page.

ichiban