Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Access persisted controls
posted

Hi there,

I have a WebTab control and add dynamically some tabs and controls/usercontrols.

My WebTab control ist configured as follows:

            tabControl.PostBackOptions.EnableAjax = true;
            tabControl.AutoPostBackFlags.SelectedIndexChanged = Infragistics.Web.UI.AutoPostBackFlag.Async;
            tabControl.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
            tabControl.EnableViewState = true;
            tabControl.EnableAjaxViewState = true;

When i search through the WebTab after the SelectedIndexChanged event i can't find/access my controls.

How can i access my controls after an async postback?

 

Thanks

  • 24497
    posted

    Hi Renatoheeb,

    Thank you for questions.
    If application creates controls dynamically by explicit adding them to Tab.Controls, then you should keep in mind following rules of dot-net architecture:
    1. Persistance of dynamic controls is not supported, but only their ViewStates.
    2. ViewState may persist only when child controls are added consistantly to the same container with exactly same IDs and without skipping not a single postback.

    The Ajax features of WebTab are applied only to postbacks inside of a tab-item (like local submit button click). They also have effect with combination of LoadOnDemand, but that is an advanced feature and it is probably not used by your application.
    All Ajax features of WebTab are irrelevant to dynamic controls. If EnableAjax is set, then webtab instantiates templates (which were set within aspx) inside of dynamically created UpdatePanels. Similar action is not possible to do with dynamic children. Any dynamic control is a final one and it is used as it is without any wrapping into possible UpdatePanel. If application needs some async features for dynamic content, then it may create UpdatePanel wrappers for its dynamic childred by itself.

    Other than that, WebTab should work by exactly same way as for any other dot-net control and application should be able to find its static and dynamic children. I created a test application which searches for static and dynamic controls within SelectedIndexChanged server event and gets/sets their values. You may test codes below in any web site.

    Note: in your attached codes the value set to AutoPostBackFlags.SelectedIndexChanged is not visible. If it is Async, then that value is a general AutoPostback option from base-class. It is not related to async postbacks defined by PostBackOptions.EnableAjax and it is not supported for content of tab items.

    aspx:
    <ig:WebTab ID="WebTab1" runat="server" Width="200px" Height="200px"
     onselectedindexchanged="WebTab1_SelectedIndexChanged">
      <Tabs>
       <ig:ContentTabItem runat="server" Text="Tab 1">
        <template>
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
        </template>
       </ig:ContentTabItem>
      </Tabs>
     <AutoPostbackFlags SelectedIndexChanged="On" />
     <PostBackOptions EnableAjax="True" />
    </ig:WebTab>

    aspx.cs:
    protected void Page_Load(object sender, EventArgs e)
    {
      if(this.WebTab1.Tabs.Count < 2)
      {
       Infragistics.Web.UI.LayoutControls.ContentTabItem tab = new Infragistics.Web.UI.LayoutControls.ContentTabItem();
       tab.Text = "Dynamic tab";
       this.WebTab1.Tabs.Add(tab);
      }
      TextBox tb = new TextBox();
      tb.ID = "TextBox2";
      this.WebTab1.Tabs[1].Controls.Add(tb);
      this.WebTab1.Tabs[1].Controls.Add(new LiteralControl("<br />"));
      Label lbl = new Label();
      lbl.ID = "Label2";
      this.WebTab1.Tabs[1].Controls.Add(lbl);
    }

    protected void WebTab1_SelectedIndexChanged(object sender, Infragistics.Web.UI.LayoutControls.TabSelectedIndexChangedEventArgs e)
    {
      string txt = "t1:" + this.TextBox1.Text;
      Control tb = this.WebTab1.Tabs[1].FindChildControl("TextBox2");
      if(tb != null)
       txt += " t2:" + ((TextBox)tb).Text;
      this.Label1.Text = txt;
      Control lbl = this.WebTab1.Tabs[1].FindChildControl("Label2");
      if(lbl != null)
       ((Label)lbl).Text = txt;
    }