ClearChildViewState does not clear the state in Composite Control

G

Goran

Hi all,

I'm developing a custom user control loader. The idea is to have a
templated control that maintains a list of user controls (ASCX files) and
then according a specified index, it loads the appropriate user control. To
select one control, a tabbed list is displayed followed by a DIV where the
selected user control is loaded.

I managed to get most things working, including events and state management,
apart from one thing. The problem I have is that when I want to reset/flush
the ViewState of a newly loaded user control (happens when switching between
tabs, i.e. user controls), some of its initial view state is still there.
(The reasoning behind this is so that the control can be treated as if it is
loaded for the first time and as a result, to perform any
databinding/initialisation it needs to do.)

For code snippets, please see below.

Thanks,
Goran

===============================================
So, I started with something along this lines in C#:
===============================================

[ParseChildren(true,"ControlDescriptors")]
public class UserControlsLoader : System.Web.UI.TemplateControl {
...
public ArrayList ControlDescriptors { get ... }

...

protected override void OnInit(EventArgs e)
{
base.OnInit (e);
if(this.Page.IsPostBack)
{
this.PerformSelection(); //it checks if the current control
needs to change from some page-registered hidden fields
if(this.IsSelectionChanged)
{
this.ClearChildViewState();
OnUserControlChanged(new
UserControlChangedArgs(this.SelectedTab)); //raises a custom event
}
}
}
....
protected override void CreateChildControls() {
//loads the HtmlControls for the tabs + the selected user
control
}
}

===============================================
I use the following in an ASPX page:
===============================================

<%@ Register TagPrefix="QQ" Namespace="xx" Assembly="xx" %>
.....
<QQ:UserControlsLoader id="qq" runat="server" SomeProperty="value">
<QQ:UserControlDescriptor Visible="true" Source="~/Components/uc1.ascx"
Name="First" />
<QQ:UserControlDescriptor Visible="true" Source="~/Components/uc2.ascx"
Name="Second" />
</QQ:UserControlsLoader>

===============================================
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top