« June 2004 | Main | August 2004 »

July 30, 2004

Dynamically replacing controls, ViewState and PostData issues

For ViewState and PostData to work correctly when restoring state to the server controls during a POST to an ASP.NET aspx page, the UniqueID’s must be the same when state is restored as they were when state was saved..

I ran into trouble when I used a button’s click event handler to remove some controls and then added some replacement controls. The replacement controls were numbered sequentially starting after the original control numbering. When a postback occurred, my override of LoadViewState created only the replacement controls which were therefore numbered differently (since the original controls were never created). ViewState wasn’t being restored correctly and the checked property of CheckBox controls wasn’t being set correctly.

What’s missing from ASP.NET is a way of updating the naming scheme originated by the removed controls’ naming managers. If this were done, the replacement controls could be named consistently.

My workaround in this situation was to do a redirect back to the page with a query string argument that causes the correct new control layout to be created.

 

 

July 26, 2004

ICSharpCode.SharpZipLib access denied

To work around an access denied error in ASP.NET applications using ICSharpCode.SharpZipLib, register the assembly in the GAC.

There’s more to it. But for a quick fix this might solve your problem.

See also:

813833 - PRB: "Access Denied" Error Messages When You Do Not Put Strong-Named Assemblies in the Global Assembly Cache - http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b813833

 

 

July 05, 2004

Viewing a byte[] array contents in a Visual Studio memory window

I haven’t found a good source of tips yet on how to make effective use of Visual Studio’s memory windows when working with C# objects, so here’s one that may work to view the contents of a byte[] array:

1.      Open the memory window.

2.      Type the name of the array in the address box, this will show you the memory occupied by the System.Array object corresponding to your byte[] array.

3.      Enter the first four byte values you see, in reverse order with a “0x” prefix, in the address box.

4.      Ignore the first two bytes, or add 2 to the address entered in step 3.