Victor Garcia Aprea : Wednesday, November 03, 2004 - Posts

Subscriptions

<September 2010>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Post Categories




Wednesday, November 03, 2004 - Posts

Nonsense Viewstate Usage (and a Lot of Microsoft Sincerity)

A few days ago I stumped at the following sample (Whidbey docs required):

 

ms-help://MS.VSCC.v80/MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/cpref/html/T_System_Web_Handlers_AssemblyResourceLoader.htm

 

In the code for that sample a custom control is built; you will find that a constructor taking two arguments is provided but not used; why is it provided at all is beyond me.

 

        public TextWithImage(string text, string imageName) {

            ViewState["Text"] = text;

            ViewState["ImageName"] = imageName;

        }

 

But what is really bad about the previous constructor? It’s the lack of sense of storing values into viewstate in a constructor when viewstate tracking has not been started yet; anything you put in there will not be persisted into viewstate.

 

As these samples are and will be followed by thousands and thousands of people I believed it was really necessary to not show such a thing. People actually learn from samples and this one will not help any in that matter.

 

So I filed this bug using LadyBug and telling:

 

Description:  Opened by vga on 2004-10-31 at 00:27:49 

                                     

In the sample used here:

 

ms-help://MS.VSCC.v80/MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/cpref/html/T_System_Web_Handlers_AssemblyResourceLoader.htm#codeExampleToggle

 

A ctor taking two arguments is provided although not used by the sample. This ctor actually stores into viewstate the two arguments passed.

 

Storing values into viewstate in a ctor is nonsense as viewstate tracking hasn't started yet thus these values won't be persisted.

 

Please consider deleting the mentioned ctor from the sample as:

 

1) its not used at all

2) its showing a nonsense usage of viewstate

 

And less than two days later I got the following (the highlighting is mine):

 

Resolution: Fixed

Closed by Microsoft on 2004-11-02 at 11:15:43 

   

Thanks for your comments,

you are right that manipulating view state in the constructor in that way is silly. I've changed the sample to have a default constructor; the control is still usable in this way and still demonstrates the important thing, which is how to use the AssemblyResourceLoader to get at some type of resource compiled with the assembly.

 

Regards, Alex 

 

 

Don’t you just love that much sincerity? :-) I know I do!

 

BTW, Alex if you happen to read this, please while you’re at it modifying the sample make sure to also change the referenced filename map6.gif to something like… map.gif? Or if you really want to get funny with filenames then you could try map872-b-northEast.gif… :-)

posted Wednesday, November 03, 2004 4:11 AM by vga with 6 Comments