Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable dynamic checkboxes on the fly in ASP - first steps

Status
Not open for further replies.

Maven4Champ

Technical User
Jun 16, 2004
154
OK guys and gals,

I have quite a task on my hands right now that has a tight deadline and I am working through the logic portion for the next day or so before going full-on high-speed development time.

So here is the back-story:
We have an ASP/vb.Net driven page that allows a table of dynamically built values and associated checkboxes to populate the table such as this:

User Input = OptionBox1 Then
Populate Date
User Input = OptionBox2 Then
Populate Different Data

The data appears as so:

tblData1:
CHECKBOX DATA_KEY DATA_VALUE
[ ] value_one Value One
[ ] value_two Value Two
[ x ] value_three Value Three

So all that being said, that works fine. What I am doing is implementing a control that feeds off another table as such:

tblData2:
DATA_KEY DATA_KEY_NOT_VALID
value_one value_two
value_two value_one
value_two value_three
value_three value_one

The meaning of this table is basically a Bridge Table which takes the data key the user chose and looks up the non-valid keys in tblData2. What I want to then do is on the fly (upon checking value_two for instance), disable the ability to check value_one or value_three. I know which key is being checked but I don't know of a way to dynamically drive the enabled/disabled behavior without hard-coding logic into VB.NET for the ASP page.

So the task is this - upon checking a dynamically built value (over 200 possible choices), I need the ability to disable certain check-boxes dynamically. The same goes for un-checking a specific value and re-enabling the new value. All the while, I must retain integrity of this logic by not allowing a "tricking" of the code by checking/un-checking certain combinations of checkboxes.

Does anyone know a good logical starting point? I realize I have thrown a lot at you all but this place is my programming salvation so I wanted to start here first.
 
this is a domain problem, not a presentation problem. yes, this needs to work at the presentation level, but that should be secondary to validating the user selections. once the user submits the values back to the page you will need to validate the data again.

what you have supplied is a small snippet, and (for me at least) I'm having difficultly understanding the total concept.

I would start like this
1. write down each rule (yes all 200 if each is different)
2. look for commonality between the rules, a way to combine rules.
3. then I would begin testing each rule (using mbunit or the like).
4. once each rule is working I would then need an engine to drive the rules.
5. I would build a rules engine and test that as well.
6. now my validation is complete. and i can integrate the rules engine into the client code. In your case the code behind.

now you also need the presentation to to dynamically adjust to user options. This (for me anyway) is a little more tricky it involves javascript and ajax. if you want the change without postbacks (with postbacks would be a terrible user experience) you would need to implement an ajax call to another URI which will return a list of "valid" options. once you have these options you will need to cycle through your list of options and update the gui appropiately.

You will need to make a decision about the scenario where an option A and B are currently checked. When checking option C (which invalidates B) what should happen?
1. should a message be displayed that says C cannot be checked until B is unchecked.
Should B be unchecked and then disabled?

for the client side I would explore how to implement this using jquery. it has built in features for ajax and makes navigating the dom easy.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
jmeckley,

Thanks for the input. I may make things simpler after having a night to think about this and I may also need to fully think the idea through but for performance and simplicity, would it be possible to do this:

1a.) Have a "Validate" button on the form that once clicked, grabs the user's selected values from the datagrid view and sticks them in some sort of array.

1b.) Build a Dataview of the exclusions from the table I built that already contains the 200+ rules and exclusion definitions, upon hitting the "Validate" button.

2.) Compare my Dataview with the array of checked values and where checkedvalue has an exclusion, return the user to the original page with a descriptive message (in a div or as an inserted read-only row in the datagrid view) notifying them that the choice is invalid.

3.) Upon resolving validation errors, hit Validate again. Once it has sucesfully validated, it returns the user to a screen that says "Submit Changes" and at this point, no further changes can be made until approved/declined.
----

My goal here is for performance and safe/sound logic. I guess my main question would be. Can I compare the checked value of an ASP Datagrid view item to a Dataview upon hitting the "Validate" button - or - is there a better way to do such a task?
 
save preformance for later, right now you just need to get it working. once it's working then you can resolve preformance problems.

if you go this route. I would solve it by:
1. get a collection of the checked checkboxes.
2. load the rules engine with all rules associated for each item.
3. for each item in the collection validate.
4. after all have been through the validation process. report validity and any messages.
Code:
IEnumerable<IRules> rules = RuleRepository.GetRulesFor(selecteCheckBoxValues);
Engine engine = new Engine(rules);
foreach(string value in selecteCheckBoxValues)
{
   engine.Validate(value);
}
bool optionsAreValid = engine.IsValid;
IEnumerable<string> errorMessages = engine.ErrorMessages;
//display results
Code:
private readonly IEnumerable<IRules> rules;
private ICollection<string> messages;

public Engine(IEnumerable<IRules> rules)
{
   this.rules = rules;
}

public void Validate(string item)
{
   foreach(IRule rule in rules)
   {
       if(rule.IsValidFor(item)) continue;
       messages.Add(rule.Message);
   }
}

public bool IsValid
{
   get { return messages.Count == 0; }
}

public IEnumerable<string> ErrorMessages
{
   get 
   { 
      foreach(string message in messages)
         yield return message;
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
jmeckley,

Thanks kindly for all of your thoughts and assistance. I am dealing in VB.NET code behind ASP.NET pages. How would your above idea translate into that environment?

I do agree with you now that I should get it working and tweak for performance afterwards. It looks like I will be pulling a a weekend-warrior on this task to make sure it gets done in time.

Your continued support is, as always, deeply appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top