Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Dynamic controls not added on postback

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
s.bussing@gmail.com - 04 Sep 2007 21:29 GMT
Hi, I have been reading for hours now, but I'm still not able to solve
my problem, though a lot of people are struggling with something
similar.

On my page I have a nested repeater. In the inner repeater for each
item a usercontrol is added which has a textbox and two buttons.

No I know that when the page is posted back (in my case by pushing one
of the buttons of the control), I have to recreate all the dynamic
control. I want to maintain the state of the controls, but thats the
second part. The first part is recreating the dynamic added controls.
Therefor I have a function which I call in the Page_Load. First I
check if the page is postedback if so, I call this function:

Private Sub ReloadDynamicControls()
       Dim _Ctrl As Control = CustomControl()
       Dim _Repeater As Repeater = Me.FindControl("rptFactor")
       For Each OuterItem As RepeaterItem In _Repeater.Items
           For Each InnerItem As RepeaterItem In
CType(OuterItem.FindControl("rptFactorItem"), Repeater).Items

InnerItem.FindControl("pnlToelichtingGedrag").Controls.Add(_Ctrl)
           Next
       Next
   End Sub

But when the page is displayed it only shows the usercontrol for the
last items of the repeater. But it should show for every item. When
I'm debugging I can see that the items are there and the usercontrol
is added to the placeholder, at least that is what I guess. But it
never shows on the page anymore.

Any helps is highly appreciated.
Thx
Mark Rae [MVP] - 04 Sep 2007 22:26 GMT
> No I know that when the page is posted back (in my case by pushing one
> of the buttons of the control), I have to recreate all the dynamic
> controls.

That's correct.

> Therefore I have a function which I call in the Page_Load.

Generally speaking, Page_Load is too far down the page cycle for creating
dynamic controls, especially if you're hoping to wire them up to events.

Try creating the dynamic controls in Page_Init instead...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Peter Bromberg [C# MVP] - 05 Sep 2007 01:42 GMT
The Repeater like its brethren DataGrid, DataList, et all all have an
ItemDataBound or RowDataBound event which you can wire up to add in your
controls. As Mark pointed out, Page_Load is usually way too late in the page
cycle to expect to be able to do it there.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> Hi, I have been reading for hours now, but I'm still not able to solve
> my problem, though a lot of people are struggling with something
[quoted text clipped - 30 lines]
> Any helps is highly appreciated.
> Thx
s.bussing@gmail.com - 05 Sep 2007 20:21 GMT
On 5 sep, 02:42, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yohohhoandabottleofrum.com> wrote:
> The Repeater like its brethren DataGrid, DataList, et all all have an
> ItemDataBound or RowDataBound event which you can wire up to add in your
[quoted text clipped - 41 lines]
> > Any helps is highly appreciated.
> > Thx

Hi Peter and Mark,

thanks for the reply. Actually I tried the page_init, but in the
example I put in the repeater items are not know a that stage. They
are only known when I bind to the controls first. This means that I
have to place the databind action into the init too. Correct?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.