tags:

views:

36

answers:

2

When and why would it be a good choice to keep the view of two different sets of information on the same page, and just change what's visible depending on different parameters?

For example, an application I'm working on has three levels of users: Admin, Director and Project Manager. We have a Managers.aspx page which follows this flow of control:

  • If user is admin, load gridview list of directors with several simple CRUD-like properties. This includes a link for each director that, when clicked, will load a new gridview with several properties of all of the Project Managers belonging to the selected director.

  • If user is director, load straight to the list of Project Managers that belong to this director, in the exact fashion as described in the second half of the "if user is admin" clause".

This is all done on one Managers.aspx page. Why? What advantage does this hold? When else might this type of situation arise? Personally, this seems like a job for two separate pages. One listing the directors, and another listing the Project Managers.

Thanks in advance :)

A: 

As you pointed out, most of the logic for those two requirements is the same: get a list of users, present them in a gridview, apply simple CRUD functions. Doing this as two separate pages would require all that code to be repeated twice, and then kept in sync.

The only real difference between the two screens is which users it shws by default... That's one if-statement of difference in a pageful of code..

Stobor
This was my initial reasoning. However, with that logic, we'd only need one page ever. If randomSetOfPropertiesForPage1 loadPage1, If randomSetOfPropertiesForPage2 loadPage2, etc. Or have I missed the point, somehow? The attributes that each column represents aren't identical across both styles of pages, and there are other slight differences..
Chris
It's a judgement call: if the pages are similar enough that you're able to get away with only a few if statements, then using one page saves you duplicating code. On the other hand, if the one page approach is as you describe, if() loadpage1, elseif() loadpage2, etc, with little overlap, then they belong in separate pages.
Stobor
A: 

As stobor indicates - when you don't want to write the same code twice.

Using the one page solution, the decision about which view to display is made on that one page. If you separate the different views out to different pages, you have to make this decision every time you need to display this data. So rather than one single if/else in Managers.aspx to determine the view, you have multiple if/else statements on multiple pages which are intended to decide whether to load AdministratorManagers.aspx or DirectorManagers.aspx.

Provided your application is robust enough, and you're not doing something stupid like determining which page to show based on a querystring value, there is no real problem using one single page to display different views. In fact, many websites do this. What you don't want to do is use seperate but identical controls for each view, because then you're just going to end up with messy code. It may make sense to create custom controls called 'AdminView' and 'DirectorView' to at least allow you to think of the two views as separate entities, but you'll have to decide for yourself whether this will be a headache-saver or a waste of time.

TomFromThePool