ClearChildViewState does not clear the state in Composite Control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default ClearChildViewState does not clear the state in Composite Control

    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>

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





    Goran Guest

  2. Similar Questions and Discussions

    1. Losing Postback state with composite controls
      Not sure how to go about explaining this, which is never a good sign. I have a Custom UserControl I've built, which contains 1 drop-down list and...
    2. Losing Composite Control property that another Composite Control ...
      Hi, I'm creating 2 composite controls in ASP.net. Control 1 is a Search control and control 2 is a Map control. I have added a property...
    3. Possible to create a composite control that has a child control that is a validator that validates the composite control itself?
      I am attempting to create a composite control which has a label, followed by an optional error message, followed by two text boxes. I have...
    4. Custom Composite Control, child User-controls loosing view state
      I've created composite custom control which dynamically creates and arranges it's child controls based on some xml data. Beside the simple web form...
    5. Using Table control in a custom composite control. Control does not render properly in design time.
      All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control...
  3. #2

    Default ClearChildViewState does not clear the state in Composite Control

    Hi,

    Which solution did you find for this problem ?

    Thanks,
    Nico.
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139