Ok I was able to use custom JS properities to create a property that specifys whether the grid is in edit/new edit mode. Now when changing tabs a javascript confirm box fires if this property is set to true. This works fine. However, if the UpdateEdit() is fired and an error comes back I need to cancel the tab change event.
For this i'm using another custom JS property called cpGridHasError. When the CustomErrorText event fires it sets a global variable GridHasError to true. Then when the CustomJSProperties event fires it sets cpGridHasError to the value of GridHasError global variable:
Boolean GridHasError = false;
protected void _gridSkillsMain_CustomErrorText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomErrorTextEventArgs e)
{
GridHasError = true;
}
protected void _gridSkillsMain_CustomJSProperties(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewClientJSPropertiesEventArgs e)
{
e.Properties["cpIsEditOrNewMode"] = _gridSkillsMain.IsNewRowEditing || _gridSkillsMain.IsEditing;
e.Properties["cpGridHasError"] = GridHasError;
}
Stepping through the events it seems to be set correctly. But when accessing this variable in javascript it is not working.
the grid.cpGridHasError comes back as false everytime. Here is a stub of the javascript the ASPxPageControl tab on changing event uses:
function TabChanging(s,e) {
var grid = null;
if (s.activeTabIndex == 3)
{
grid = window.frames["_gridskills"]._gridSkillsMain;
if (grid.cpIsEditOrNewMode)
{
if (confirm("Do you want to save changes?")) {
grid.UpdateEdit();
if (grid.cpGridHasError) {
e.cancel = true;
return;
}
}
else
{
grid.CancelEdit();
}
}
}
}
I think the problem arises is that the grid.UpdateEdit() doesn't return an error until after the ASPxPageControl OnTabChange event finishes, however, I then waited to check that same property after the UpdateEdit() ran on the TabChanged event and if the cpGridHasError property is set to true I then change back to the previous tab, however, again the cpGridHasError is false.
Is there a way arround this.
Again this is the scenerio i'm trying to achieve:
Grid is in edit or new edit mode. The grid is in a ASPxPageControl. User changes tabs without saving or canceling out of edit mode. Javascript prompts if the user wishes to save or cancel changes. If the user selects save, the UpdateEdit() runs, and the tab changes. However, if the UpdateEdit() returns a error, the tab page should either cancel or the tab should change back to the tab the grid is on with the error.
I can't seem to acheive this result. Thanks.