views:

11

answers:

1

Hi

I have a peculiar situation at hand in which I need to validate a pair of dates in an ASP.Net web app.This is how my page looks like :

I have a "From Date" field which consists a set of three dropdownlists ( for Year , Month and Date) I have a "To Date" field which also consists a set of three dropdownlists ( for Year , Month and Date). There is a "Download Report" button on the screen ( which allows a user to download a report for the specified date range)

All these six dropdownlists are wrapped in a user control.

Now all the 6 dropdownlists have a default "please select" value. When a user lands on the page for the first time , all dropdownlists are set to "please select". The "Download" button is enabled only after valid 'From' and 'To' dates are selected.

Now my requirement is that :

When a user lands on the page for the first time , no attempt to validate the dates should be made until he selects all the 6 dropdownlists at least once.

When the 6th dropdownlist is selected , the From and To dates should be validated. Once a user has selected all 6 dropdowns once , subsequently on every dropdownlist postback , the dates should be validated.

My Issue:

What's the best way to track these 6 distinct postbacks ( for each of the dropdowns) before starting to validate the From and To Dates. I could maintain a flagin ViewState .. but is there a better way ?

Thanks in advance !

+1  A: 

I don't believe you should think of these as 6 distinct postbacks. It is likely that the user might select a value from one of the drop downs and then change it back to "Please select"; this way it could be many postbacks before a valid value is selected.

Also talking of distinct postbacks does not mean that this will be an ordered process, ToDate could be selected before FromDate.

So I would suggest that you - before doing any date validation - make sure all drop down boxes have a value selected and only if so, move to the next level of validation (e.g. to make sure 30th Feb is not selected).

I would personally not use the ViewState at all, and in fact Web forms for that matter - but that is not relevant to your question...

Aliostad