views:

34

answers:

1

Hello experts,

I've a scenario where I want to calculate the no of records in repeater which is in user control and display the count in a literal which is in page(ex default.aspx). How can I achieve this ? I don't wanna use public properties....i want to do it by creating my own custom event.

Any help or suggestion would be highly appreciated.

Thanks, Sumit Arora

+1  A: 

Create a property in the user control:

public int NumberOfRecords { get { return myRepeater.Items.Count; } }

Then, in the Page_Load:

countLabel.Text = string.Format("Number of records: {0}", myUserControl.NumberOfRecords);
onof
Well the problem in this case is that the page load of Page will be called first and then the page load of user control will be called....so how can I get the value of the property in the page load of the page?It won't give me any record.
Sumit
You could force the databind in the page_load, before calling the property. Or put the countLabel.Text = ... in the Page_OnPreRender.
onof