views:

46

answers:

1

I was going through Scott's list of .NET questions at http://www.hanselman.com/blog/WhatGreatNETDevelopersOughtToKnowMoreNETInterviewQuestions.aspx

In a comment there is a scenario - You are reviewing an ASP.NET application and find that the viewstate is storing "id", which is being used for different unrelated purposes on different pages. Perhaps for PersonID in one page, productID on other page etc.

What will your recommendation be?

A: 

I don't see a problem wih this. Each page, and therefore each ViewState instance, has a different context. There is no connection of the ViewState items in one page to the ViewState items in another page, so there is no chance of confusing them. The nature of the 'id' should be obvious when coding the page - it is a person id, a product id, a customer id, or whatever.

Ray
But doesn't it look to be a slight design/architecture issue, which may cause maintainence headaches in future?
Saurabh Kumar
I don't think so. I use something similar in my urls - I use a standard 'item_id' parameter for any page which need an id. It make some of my code simpler (creating the urls, reading the id from the urls, storing the ids in ViewState). Each page knows what type of id it expects and can behave accordingly. Obviously, if some page needs multiple ids to do its thing, each will need a different name, but I don't have many of these.
Ray