Showing posts with label contents. Show all posts
Showing posts with label contents. Show all posts

Monday, March 26, 2012

Instantiate Accordion content

Hi,

I have an accordion with some panes that have custom controls in their content templates.

The accordion is NOT databound ... the contents are static, though viewstate is helping keep track of the values in the custom controls.

When the page is created for the very first time, NOT postback, the accordion panes do not instantiate the user controls until sometime during the OnPreRender stage in the lifecycle.

On subsequent postbacks however, the accordion panes do instantiate their controls during the LoadState stage, due to their presence in ViewState.

How can I make the accordion panes instantiate their content templates earlier than OnPreRender when the page is created for the first time?

The accordion pane's content templates are not dynamic. They are coded into the page markup.

I have tried calling something like Accordion.Panes[0].Content.InstantiateIn(Accordion.Panes[0]) and various combinations at various stages, but I usually ended up just getting duplicate versions of the controls in the wrong places in the page!

I could not find any "EnsureControls()" methods available in the accordion.

Many thanks in advance for your helpful suggestions,

Ben

Hi,
Accordion.Panes[0].FindControl('nothing') will make pane 0 to instantiate its templates. FindControl is an indirect way to call EnsureChildControls.

-yuriy
http://couldbedone.blogspot.com


Yuriy! Thank you so much! I'm relieved!

Wednesday, March 21, 2012

Is it a problem for Accordion Contents to Dynamically Change upon postbacks

I want to ensure that what I am trying to do is possible with an accordion control. I want to dynamically change the contents of panels during the life of a page in response to a postbacks. Do all of the controls have to exist upon initial creation in the page load? I am getting view state errors from time to time and don't know the cause. I have tried creating a large number of controls initially and then just making visible the ones that I want to display and making invisible the ones I want to stop displaying upon the postback. I also move the objects around within the html and within htmltables. Should what I am describing here work?

Follow-up to my own post: I've concluded that it is NOT OK to move the dynamically created controls around on an accordian panel during a postback. So what I am doing as a solution is to create all possible controls needed in advance and then making the ones needed be visible=true and not needed be visible=false. This seems to work from initial testing. Feel free to comment on this, thanks, but this is probably resolved.