Geeks With Blogs

News Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009


I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes www.pageflakes.com.
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta realestatebazaar.com.bd an ASP.NET MVC application written in C#.NET.


Some of 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

Shahed Khan blog

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

Posted on Saturday, May 3, 2008 3:31 AM | Back to top


Comments on this post: ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls

# re: ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls
Requesting Gravatar...
:) a bit like wave-particle duality... Observation of the experiment alters the result!
Left by lisa on May 06, 2008 7:34 PM

# re: ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls
Requesting Gravatar...
Any solution concerning this bug? I've found the same difficulty ...
Thanks for your reply!
Rodrigo
Left by Rodrigo on Jul 30, 2008 5:40 AM

# re: ASP.NET Bug, Multi View control do not save ViewState, of dynamically added controls
Requesting Gravatar...
Can somebody plz share the solution for this bug?
-Dipesh
Left by Dipesh on Oct 22, 2009 2:15 PM

Your comment:
 (will show your gravatar)


Copyright © Shahed Khan | Powered by: GeeksWithBlogs.net