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>
===============================================
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>
===============================================