v
Not logged inv
SearchAsk a QuestionReport an IssueMake a SuggestionMy Questions and Issues
Issue Details
Find By ID

Force update on ASPxGridView in edit mode on tab change event.

Issue Details

Log in to Track Changes or Edit
Q131273
Question
Dave R
Yes
Processed
Answered
.NET
ASPxGridView and Editors Suite
8.1.6
Windows Server 2003
Microsoft Visual Studio 2008
10/2/2008 2:14:23 PM
-> Created by Dave R 9/30/2008 10:23:45 PM

We have an application in which there are several tabs using the ASPxPageControl. In some of the tabs there are ASPxGridViews. These grids have edit forms allowed.

When a user edits the grid they must hit either update/cancel for those effects to take change. However, if they forget and switch tabs there is nothing to notify them. Using the ASPxPageControl ontabchange client function I would like to create a javascript call to confirm that they wish to save or cancel the change.

Is there an ASPxGridView client method that I can call that forces an update or cancel based on the confirm box? Thanks.

P.S. You have an awesome product and I very much enjoy working with your controls. Your support is excellent as well, keep up the good work!

<- Reviewed by DevExpress Team 10/1/2008 6:39:09 AM
<- Processed (Answered) by DevExpress Team 10/1/2008 12:52:39 PM

Hi Dave;

ASPxGridView has the client-side UpdateEdit() method that saves all the changes made. I beleive you can use this method to solve your task.
If you need some additional information, please let me know.

Thanks
Kate.

-> Reactivated by Dave R 10/1/2008 3:21:03 PM

Ok i see that UpdateEdit() and CancelEdit() work to use client-code. However, how do I check if the grid is in editing mode or in a new row edit mode? I don't see anything in the client-code that determines this like in the server code.

<- Processed (Answered) by DevExpress Team 10/1/2008 3:37:30 PM

Hi Dave;

I'm afraid, you can't do it especially in the client-side. However, ASPxGridView has the CustomJSProperties event that allow to check if the grid is in edit (IsEditing property) or in new row editing (IsNewRowEditing property) mode.
Please check this help topic for more information about this event:

ASPxGridView.CustomJSProperties Event

If you need more information, please let me know.

Thanks
Kate.

-> Reactivated by Dave R 10/1/2008 7:36:33 PM

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.

<- Processed (Answered) by DevExpress Team 10/2/2008 2:14:23 PM

Hi Dave;

I think, this issue is caused by the fact that this client-side script is executed before the trip to the server. So, the cpGridHasError property is always false in the client-side.
I suggest you the following solution:

[JScript]

var index; //global js variable

// the TabChanged event handler of ASPxPageControl:
          if (grid.cpIsEditing)
             {
                   if (confirm("Do you want to save changes?")) {
                      e.cancel = true;
                      grid.UpdateEdit();
                      index = e.tab.index;
 
              }
}

//the EndCalback event handler or ASPxGridView:

if (!s.cpHasErrors)
        {
      if (!index == null)
    {
      var tab = tabControl.GetTab(index);//tabControl is the ClientInstanceName of ASPxPageControl
      tabControl.SetActiveTab(tab);
    }
         }

Thanks
Kate.

Log in to Track Changes or Edit

Peer-to-Peer Discussion in DevExpress Forums

No discussion on this article has been started yet.

Please login to start discussion.

v
v
Search
Searching Tips