I’m testing with the ASPxperience controls. I have a simple CallbackPanel, with inside a textbox and a PageControl.
Just for testing, I have a button placed under the callbackpanel. On click, I want to add an extra tab to the PageControl.
markup:
<dx:ASPxCallbackPanel ID="ASPxCallbackPanel1" runat="server" Width="200px" OnCallback="ASPxCallbackPanel1_Callback1">
<PanelCollection>
<dx:PanelContent runat="server">
<dx:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="0" ClientInstanceName="PageControl1"
Height="359px" Width="538px">
<TabPages>
<dx:TabPage>
<ContentCollection>
<dx:ContentControl runat="server">
</dx:ContentControl>
</ContentCollection>
</dx:TabPage>
</TabPages>
</dx:ASPxPageControl>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
<input id="Button1" type="button" value="button" onclick="ASPxCallbackPanel1.PerformCallback('addtab');" />
Codebehind
protected void ASPxCallbackPanel1_Callback1(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
ASPxPageControl1.TabPages.Add("Test");
TextBox1.Text += "1";
}
Now the strange thing is that each time you click the button, in the textbox there’s always ‘1’ added to the content of the textbox. So if you click 5 times it will display : ‘11111’.
However, the PageControl always deletes (or forgets or ignores?) the previous added tab so you’re always left with just 1 extra tab named ‘test’.
How does this come? I don’t understand ? (I’m fairly new to this control suite)
With an
ASPxCallbackPanel‘s you can accessViewState, because it is sent to the server, but that sameViewStatecan’t be changed server-side during a callback, so it isn’t updated at the end. This behavior is by design so you can’t do much about it.In your particular case the only state known is the one loaded at the first page load so, on callbacks, the only known TabPage is the one at markup.
You can either:
Design all your tabs on markup (or on first load for that matter) and make them visible/invisible using ASPxPageControl client-side API and ASPxTabPage client-side API.
Use UpdatePanel which allows you to access and change
ViewState.