posts - 216, comments - 198, trackbacks - 68

My Links

News




I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net) and born in Bangladesh.
I work for Ocean Informatics Pty Ltd as a Senior Developer - Analyst.
I am also co-founder and core developer of Pageflakes www.pageflakes.com
and most recently created SmartCodeGenerator

My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls

Couple of days back me and my colleague, we discovered an issue with the ASP.NET Multi View Control.
We were surprised  to see that it do not add ViewState, of the dynamically added controls, of the Inactive Tabs.

ASP.NET 2.0

       <asp:MultiView ID="MultiView1" runat="server" EnableViewState="true">       
        </asp:MultiView>

C# Code Behind

        if (!IsPostBack)
        {
            int index = 1;
            foreach (View v in MultiView1.Views)
            {                
                    TextBox t = new TextBox();
                    t.ID = index.ToString();
                    t.Text = "This text will not be assigned, to any Inactive Tabs, unless you put a breakpoint on this line and watch the value of this line explicitly";
                    v.Controls.Add(t);
                    index = index + 1;                
            }
        }

 

Surprisingly, you will notice only the Textbox.Text of the Active Tab will have value,
however if you go to any other Tab of the MultiViewControl, you will notice that the TextBoxes are empty.

After investigating further we realized that the Viewstates of the dynamically added controls are not saved (for any of the inactive tabs).
It became more interesting, when we started to debug, by putting a breakpoint to watch TextBox.Text, surprisingly every TextBox gets populated with desired Text ( for all tabs including the inactive tab, only when you explicitly watch ). Also it saves all ViewState correctly.

Not sure whether its a bug,  the ASP.NET team may have wanted this behavior to enhance performance of the Multi View control,

but if that is the case, why does it populate the TextBox.Text and also saves into Viewstate, when we try to debug !!!

 

Do not believe me?  Try it by yourself !!

Print | posted on Saturday, May 03, 2008 3:31 AM |


Feedback

# re: ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls

:) a bit like wave-particle duality... Observation of the experiment alters the result! 5/6/2008 7:34 PM | lisa

# re: ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls

Any solution concerning this bug? I've found the same difficulty ...
Thanks for your reply!
Rodrigo 7/30/2008 5:40 AM | Rodrigo

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 2 and 3 and type the answer here:

Powered by: