Enterprise Library (.NET 2.0) release

Published 1/21/2006 by Henry in EntLib
Tags:

The long-awaited update to Enterprise Library for .NET Framework 2.0 is now available - the official release is branded January 2006.

Enterprise Library for .NET Framework 2.0 Now Available! 

Enterprise Library for .NET 2.0

This release of Enterprise Library includes six application blocks (Caching, Cryptography, Data Access, Exception Handling, Logging and Security), and provides similar functionality to the previous releases for the .NET Framework 1.1; however, Enterprise Library has been redesigned to use the new capabilities of the .NET Framework 2.0.

Go to patterns & practices: Enterprise Library

 

Henry Cordes
My thoughts exactly...


Viewstate and Postback

Published 1/12/2006 by Henry in ASP.NET | C#
Tags: ,

While working on an ASP.NET project I am building kind of a wizard. There will be dynamically created input controls like textboxes, dropdownlists, radiolists etc. So I built controls that contain validation etc.
But between postbacks, while dynamically creating "new" wizardforms (different controls than on the previous one) the viewstate cannot handle this anymore.

The following information is available:

Stacktrace starts with:
[InvalidCastException: Specified cast is not valid.]
   System.Web.UI.StateBag.LoadViewState(Object state)
   etc, etc.

So on a page that contains controls, when dynamically creating controls on this page after a postback there can arise a problem with the viewstate. I consider this to be a bug, but Microsoft explains the reason why in another manner.

After asking Uncle Google I learnt the following from the MSDN website
Dynamic controls and ViewState

MSDN website:
In most scenarios, this view state processing model works fine. Typically, you add dynamic controls to the end of a container's collection of controls. The view state information stored for the dynamic controls is therefore extra information at the end of the view state structure for the appropriate container, and the page can ignore it until after the controls are created.
However, view state information about dynamically created controls can be a problem in two scenarios:

If you insert dynamic controls between existing controls.
If you insert controls dynamically and then reinsert them during a round trip, but with different values.
If you insert dynamic controls between existing controls, the dynamic control's view state information is inserted into the corresponding location of the view state structure. When the page is posted and the view state is loaded, the dynamic control does not yet exist; therefore, the extra information in view state does not correspond to the right control. The result is usually an error indicating an invalid cast.

In other words, sorry we cannot do this with ASP.NET.
I tried to sit back and think the problem over:

After postbacks I cannot rebuild the page with new controls.

Solution:
Store necessary state info in Session and use Response.Redirect(url); to redirect the aspx page to itself.

Microsoft does not even mention this in the article.

Henry Cordes
My thoughts exactly... 


Happy newyear!

Published 1/1/2006 by Henry in Fun
Tags:

Happy newyear!
A very happy 2006

Henry Cordes
My thoughts exactly...