Objective: To develop an UI for multiple choice questions
What I did: I have made a user control with Question Text and Radio Button List for the answers and tested it by fetching data from DB and it works just fine the way I wanted
Note: I am using master page
Next: I wanted to put this user control inside a repeater control and then populate it dynamically. Following is the markup of my web form
Problem: The events i.e. OnItemCreated="Repeater1_ItemCreated" OnItemDataBound="Repeater1_ItemDataBound" OnItemCommand="Repeater1_ItemCommand" are not firing
In the page load of web form (not user control) I tried to do something like this
string ss;
foreach (RepeaterItem ri in Repeater1.Items)
{
ss = "aa";
}
The intention is just to see what is inside the repeater control, but debugger never enters the loop.
Also trust me that almost four hours of googling gave me no result. There is no clear and concrete example available.
There are public properties inside the User Control (.ascx) which are used to populate the controls (e.g. text box, radio buttons etc.)
Then in the page load method of page (.aspx) I am making a trip to the BLL (get some data) and tries to set the public properties of the user control. Note please that this page is hosting the user control inside the Repeater Control (item and alternating
template). The two instances of the user control are having unique ids as well.
I can try to move this logic mentioned in step 2 above to the Page Init method, but I will do that when I come to the stage of page post back and redrawing things again.
The other problem is that in the page load method I am unable to get a reference to the Unique Ids of the user control, so then I tried things like this
foreach (RepeaterItem ri in Repeater1.Items)
{
// here i had break point just to see the type of items/control available
}
FutureGuru
Member
57 Points
82 Posts
User Control inside a Repeater Control does not work
Feb 26, 2013 01:08 AM|LINK
Objective: To develop an UI for multiple choice questions
What I did: I have made a user control with Question Text and Radio Button List for the answers and tested it by fetching data from DB and it works just fine the way I wanted
Note: I am using master page
Next: I wanted to put this user control inside a repeater control and then populate it dynamically. Following is the markup of my web form
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> <asp:Repeater ID="Repeater1" runat="server" OnItemCreated="Repeater1_ItemCreated" OnItemDataBound="Repeater1_ItemDataBound" OnItemCommand="Repeater1_ItemCommand" > <ItemTemplate> <uc1:UCQuestion runat="server" id="UCQuestion1" /> </ItemTemplate> <AlternatingItemTemplate> <uc1:UCQuestion runat="server" id="UCQuestion2" /> </AlternatingItemTemplate> </asp:Repeater> </asp:Content>Problem: The events i.e. OnItemCreated="Repeater1_ItemCreated" OnItemDataBound="Repeater1_ItemDataBound" OnItemCommand="Repeater1_ItemCommand" are not firing
In the page load of web form (not user control) I tried to do something like this
string ss; foreach (RepeaterItem ri in Repeater1.Items) { ss = "aa"; }The intention is just to see what is inside the repeater control, but debugger never enters the loop.
Also trust me that almost four hours of googling gave me no result. There is no clear and concrete example available.
MetalAsp.Net
All-Star
112752 Points
18373 Posts
Moderator
Re: User Control inside a Repeater Control does not work
Feb 26, 2013 04:13 AM|LINK
Where/how are you databinding the repeater?
FutureGuru
Member
57 Points
82 Posts
Re: User Control inside a Repeater Control does not work
Feb 26, 2013 02:28 PM|LINK
Thanks for the reply.
foreach (RepeaterItem ri in Repeater1.Items) { // here i had break point just to see the type of items/control available }but I can't get inside the loop.