views:

262

answers:

1

I'm currently building a user control that displays a message when a Repeater is empty.

The idea is simple, provide the user control with the ID of the Repeater. When the user control is rendered look up the Repeater and check Items.Count. If it's zero then display the message.

I would like to add one more feature though. I want to be able to hide the Repeater if there are no Items.

Obviously I can't do this in protected override void Render(HtmlTextWriter writer) because the Repeater has (possibly) already been rendered. I also can't do this when the the Repeater ID is assigned to the user control, as the databinding hasn't happened yet.

So my question is.. what event can I override in my user control where databinding has occurred, but rendering has not.

+1  A: 

Consider the Page's PreRender event. That way binding has happened but nothing has yet been rendered although they are just about to.

AnthonyWJones
I need all the code to be in my User Control though.
James
Oh.. actually I think I know what you mean. I can add a `protected void Page_PreRender(object sender, EventArgs e)` signature to my User Control. I will try that.
James
Yes, that did the trick. Thanks.
James