Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
360
"Enter" on RowAdding causes strange postback with BatchUpdating="true" when ExitingEditMode is canceled before; cannot catch ENTER on KeyDown
posted

Hello again,

 

due to a bug with the ASP.NET validators not working when the WebDataGrid is inside a WebSplitter (see http://ko.infragistics.com/community/forums/t/90599.aspx), we have to find another way of validating client-side. Let's take the RowAdding (CellEditing is similar and has the same problems) for example, where we have now encountered a very strange issue.

 

Basically what we want to do is: on ExitingEditMode (client-side), validate the current cell (via e.getCell() and e.get_displayText()), and if it's invalid, use e.set_cancel(true). That works perfectly fine when clicking out of the cell, or using TAB or arrow keys to change cells. But it doesnotwork when trying to add the "add new row" to the grid by pressing ENTER. To be more precise: if the cell is valid, on ENTER the row gets added to the grid via BatchUpdating and there isnopostback. But if the cell is invalid, the ExitingEditMode event is canceled (which we want), but somehow a postback happens that loses all of the information entered in the "add new row". This shouldn't be happening at all, since BatchUpdating is enabled.

 

We're at a loss now. I will post the code below, but so much work has already gone into trying to get client-side validation to work (first with ASP.NET validators which the WebSplitter doesn't do, now with the client events acting strange) and the now, that time is really running out for us, dead-line wise...

 

I again hope that I have misunderstood something about your controls so that it's easy to fix this time, but last time it was an unexpected behavior; hopefully it's not this time, because I wouldn't know how to work around the workaround :/

 

Please help me solve this quickly! I will post the code now (omitting the sample data, which plays no role here anyway). We use Infragistics 14.1 with the latest SR on Win7 64 bit, VS 2013 U2, IE10. I will also upload a slightly more sophisticated sample project showcasing this issue.

The grid:

 <ig:WebDataGrid ID="WebDataGrid1"runat="server" AutoGenerateColumns="false" Height="350px" Width="400px" ClientEvents-KeyDown="keyDown"       DataKeyFields="ID">

<Columns>

<ig:BoundDataField Key="Prename" DataFieldName="Prename" />

<ig:BoundDataField Key="Surname" DataFieldName="Surname" />

</Columns>

<Behaviors>

<ig:Activation />

<ig:EditingCore BatchUpdating="true">

<Behaviors>

<ig:RowAdding>

<AddNewRowClientEvents ExitingEditMode="onExitingEditMode" />

<EditModeActions MouseClick="Single" EnableOnActive="true" />

</ig:RowAdding>

<ig:CellEditing CellEditingClientEvents-ExitingEditMode="onExitingEditMode" />

</Behaviors>

</ig:EditingCore>

</Behaviors>

</ig:WebDataGrid>

 

The javascript handlers:

 

function onExitingEditMode(sender, e) {

  e.set_cancel(true);

}

 

function keyDown(sender, e) {

  if (e.get_browserEvent().keyCode == 13) {

    var i = 0; // used for breakpoint

  }

}

 

With this setup, I click in a row adding cell, press ENTER, and a postback happens. How can we work around this or disable this behavior? I know that ENTER is supposed to commit, but with BatchUpdating, there shouldn't be a postback, especially because in this case nothing is even added to the grid; nothing should happen at all.

 

Now to our next, related problem, which happened when trying to find a workaround: We tried to use the KeyDown property of the grid to catch ENTER. If the ExitingEditMode event of the current cell iscanceled(if the cell is invalid), the breakpoint is hit, but we have to validate all cells of the add new row on ENTER (because some could be empty, which we don't want). Now if the current cell is valid, but one of the others is not, the ExitingEditMode event isnot canceled, and then for some reason the breakpoint is not hit and ENTER not caught.

 

How can we either disable ENTER from causing that weird postback, or catch the ENTER key when it is pressed in a valid cell?

 

In the sample project: If you press enter when in an empty add new row cell, the strange postback happens and ENTER is caught. But if you type something in one of the two add new row cells (the other is empty) and press ENTER, the KeyDown event doesn't run into the breakpoint, so we cannot even cancel this there... We are out of ideas soon I guess :/ It would be very kind if one of the experts could help us get around this. Thanks very much in advance!

CancelRowAddingTest.zip