posts - 236, comments - 436, trackbacks - 56

My Links

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

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

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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

Feedback

Gravatar

# 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
Gravatar

# 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
Gravatar

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

Can somebody plz share the solution for this bug?
-Dipesh
10/22/2009 2:15 PM | Dipesh
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: