Monday, March 26, 2012

Cell colors odd behaviour in DetailsView

I have a page with an Atlas updatePanel and a detailsview in editMode.

I also have a save button that is responsible for updating the detailsview and run a custom command (runChecks) that basically does the following:

- check if a textbox in the detailsview is within a specific range of values; if it is not, color the detailsview's cell in red;

Currently the SaveButton Command code is:

runChecks(); DetailsView1.UpdateItem(true);//DetailsView1.Dispose(); DetailsView1_DataBound(sender, e);

My problem is that if I change the value from "good" to "bad" and click the save button, the cell is not colored red. It only changes color if I refresh the page.

Oddly, if I change from "bad" to "good", I don't need the refresh for the color to be in its default value.

If the TextBox's autopostBack is set to true, the cell will become colored red after I change it to a "bad" value but the color dissappears when I click save. Again, it will reappear in red if I refresh the page.

Why is this happening and how can I prevent the red color from dissappear when I click save?

Thank you!

FYI, what the runChecks currently does is:

protected void runChecks() {bool valid =true; DemographicsCriteria criteria =new DemographicsCriteria(1,null,null); valid = valid && criteria.editCheck("Age", ((TextBox)DetailsView1.FindControl("ageTextBox")).Text, DetailsView1.Rows[2].Cells[1]); valid = valid && criteria.editCheck("Gender", ((RadioButtonList)DetailsView1.FindControl("genderRB")).SelectedValue, DetailsView1.Rows[3].Cells[1]);if (valid ==false) { warningLabel.Visible =true; }else { warningLabel.Visible =false; } }

where editCheck is:

public bool editCheck(string filter,string value, TableCell cell) { DataRow[] criteriaRow;switch (filter) {case"Age": {int valueInt = _code.convertStringToInt(value); criteriaRow = selectDemographicsCriteria(filter);if (((int)criteriaRow[0][_minimumVIndex]) >= valueInt || valueInt >= ((int)criteriaRow[0][_maximumVIndex])) { cell.BackColor = _errorColor;return false; }else {return true; } }break;case"Gender": {if (value !="M") { cell.BackColor = _errorColor;return false; }else {return true; } }break;default:return true;break; } }

No comments:

Post a Comment