Problem with dynamicly added buttons in PlaceHolder




I have created a custom repeater with a custom template.

In the custom template I can place custom controls that are for my
repeater. I have made custom buttons and a custom placeholder.

I add the buttons and placeholder to my template and everything works
alright. I add clickevents to my buttons and that works aswell, but when
I dynamicly add buttons to my placeholder and from them try to add a
clickevent it wont raise that event on the postback.

That is probably since the buttons in the placeholder is not created on
the postback, so that is kind of the source of the problem. But Im
stuck, and dont know how to move on. I post some code, and call for help :)

public class customRepeater : Repeater{

private PagedDataSource pds;

public PagedRepeater() : base()
pds = new PagedDataSource();

public override object DataSource
get {return base.DataSource;}
pds.DataSource = (IEnumerable) value;
base.DataSource = pds;

public override void CreateControlHierarchy(bool useDataSource)

PagedRepeaterTemplateItem item = new PagedRepeaterTemplateItem();

PagedRepeaterTemplateButton first = (PagedRepeaterTemplateButton)
first.Click += new EventHandler(First_Click);

PagedRepeaterTemplatePages pagesHolder =
(PagedRepeaterTemplatePages) item.FindControl("plcPages");


base.CreateControlHierarchy (useDataSource);

private void FillPlaceHolderWithPages(PagedRepeaterTemplatePages plcH)

for (int i=pds.CurrentPageIndex; i<=pds.PageCount;i++)
LinkButton lb = new LinkButton();
lb.Text = i.ToString();
lb.CommandArgument = i.ToString();
lb.Click += new EventHandler(Page_Click);


The First_Click event is triggered as it should, but the Page_Click is
not. That is as I said before because the pds.PageCount is 0 after a

I am thinking of storing the PageCount in the viewstate to maintain,
that could work, but it doesnt seem like the best solution. Any ideas?


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