Problem with Repeaters, Dynamic controls, and postback

Joined
Mar 21, 2009
Messages
2
Reaction score
0
I'll try to boil down my situation:

I have one Repeater and inside the ItemTemplate, I have some controls - a dropdown, a textbox, and a placeholder.

Upon ItemDataBound, I execute some SQL in the codebehind which builds some dynamic controls (including another dropdown) inside the placeholder.

I have a Save button. When the user clicks the Save button, the intention is to to a DB update of all three controls - the dropdown and textbox in the ItemTemplate AND the dropdowns that were dynamically created in the PlaceHolder.

Inside my SaveButton_Clicked event, I iterate through all the RepeaterItems and attempt to do the database updates.

Here's what happens-

1. If I put the following in my Page_Load:

Code:
if(IsPostBack) 
  Repeater1.DataBind();

then the controls inside the PlaceHolder will update the database properly, but the controls in the ItemTemplate are reset to Databound values and will not update the DB.

2. If I don't do that DataBind as above, then the controls in the ItempTemplate will update the database, but the dynamic controls inside the placeholder will not.

3. I tried splitting it into two loops and doing a DataBind() in between. That didn't work either. After properly updating the outer controls and doing the DataBind(), the controls inside the PlaceHolder didn't even exist anymore.

I'm at my wits' end. I can have one or the other, but not both. What am I missing? The crux of the matter seems to be the proper sequence of binding to the DB, building the dymamic controls, waiting for their postback values to be loaded, and then reading from them to update the DB.

I can post more details if necessary, or the full code even if that helps.

Thanks in advance for any light you can shed on this problem.

Here's an outline of my aspx:

Code:
Repeater
  ItemTemplate
    DropDownList
    TextBox
    PlaceHolder

after binding and codebehind builds the controls, we get
Code:
Repeater
  ItemTemplate
    DropDownList
    TextBox
    PlaceHolder
       DropDownList
       DropDownList
       ...
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top