iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi
Please have a look on follow Code sequence.
ClientSideEvent grd_OnBeforeDelete, grd_OnBeforeAdd and grd_OnAfterDelete are not fired!
ClientSideEvent grd_OnBeforeRowSelect, grd_OnCellDblClick works fine!
Why?
AllowAddNew and AllowDelete are set to Yes on ServerSideEvent grd_InitializeLayout.
<%@ Page Title="" Language="C#" MasterPageFile="~/Relays/Masterdata/MasterData.master" AutoEventWireup="true" CodeBehind="Errorlist.aspx.cs" Inherits="QS_Client.Relays.Masterdata.Errorlist" %> <%@ Register assembly="ISNet.WebUI.WebDesktop" namespace="ISNet.WebUI.WebDesktop" tagprefix="ISWebDesktop" %> <%@ Register assembly="ISNet.WebUI.WebGrid" namespace="ISNet.WebUI.WebGrid" tagprefix="ISWebGrid" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <script language="javascript" type="text/javascript" id="grd_OnBeforeDelete"> <!-- function grd_OnBeforeDelete(controlId, tblName, rowObject) { var grd = ISGetObject(controlId); alert("grd_OnBeforeDelete"); return true; } --> </script> <script language="javascript" type="text/javascript" id="grd_OnBeforeRowSelect"> <!-- function grd_OnBeforeRowSelect(controlId, tblName, lastSelectedObject) { var grd = ISGetObject(controlId); alert("grd_OnBeforeRowSelect"); return true; } --> </script> <script language="javascript" type="text/javascript" id="grd_OnBeforeAdd"> <!-- function grd_OnBeforeAdd(controlId, tblName, rowObject) { var grd = ISGetObject(controlId); alert("grd_OnBeforeAdd"); return true; } --> </script> <script language="javascript" type="text/javascript" id="grd_OnAfterDelete"> <!-- function grd_OnAfterDelete(controlId, tblName, rowObject, xmlResponseObject) { var grd = ISGetObject(controlId); alert("grd_OnAfterDelete"); return true; } --> </script> <script language="javascript" type="text/javascript" id="grd_OnCellDblClick"> <!-- function grd_OnCellDblClick(controlId, tblName, rowIndex, cellIndex, cellEl) { var grd = ISGetObject(controlId); alert("grd_OnCellDblClick"); return true; } --> </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="cphMasterdata" runat="server"> <ISWebGrid:WebGrid ID="grd" runat="server" Height="250px" oninitializelayout="grd_InitializeLayout" UseDefaultStyle="True" Width="500px" oninitializedatasource="grd_InitializeDataSource" oninitializerow="grd_InitializeRow" onpreparedatabinding="grd_PrepareDataBinding" onbatchupdate="grd_BatchUpdate"> <LayoutSettings> <ClientSideEvents OnBeforeDelete="grd_OnBeforeDelete" OnBeforeRowSelect="grd_OnBeforeRowSelect" OnBeforeAdd="grd_OnBeforeAdd" OnAfterDelete="grd_OnAfterDelete" OnCellDblClick="grd_OnCellDblClick" /> </LayoutSettings> </ISWebGrid:WebGrid> </asp:Content>
Now, I use ClientSideEvent OnAcceptAllChanges. Perhaps, somebody knows a better wayfunction grd_OnAcceptAllChanges(controlId){ var grd = ISGetObject(controlId); var DelChanges = grd.GetChanges("Deleted"); for (var i in DelChanges) { if (DelChanges[i].Row.GetCell("Dependencies").Value != "0") { DelChanges[i].Row.UndoChanges(); } } return true; }
Now, I use ClientSideEvent OnAcceptAllChanges. Perhaps, somebody knows a better way
function grd_OnAcceptAllChanges(controlId){ var grd = ISGetObject(controlId); var DelChanges = grd.GetChanges("Deleted"); for (var i in DelChanges) { if (DelChanges[i].Row.GetCell("Dependencies").Value != "0") { DelChanges[i].Row.UndoChanges(); } } return true; }
Michael,
I think your code is already good and decent. That should be the best way to achieve your scenario.
- James.
It appears that the OnBeforeXXX and OnAfterXXX for editing-type operations will be fired only in normal updating mode (non batch updating).
I think the reason is because batch update has its own specific events such as OnAcceptAllChanges, OnAddPendingChanges, OnUndoChanges and OnUndoAllChanges which supercede the basic editing events.
Hope this helps, James.
As James has said, those events will be fired only in normal updating mode, not for BatchUpdate scenario. I am sure that the information from James has already answered your question.
Regards,Handy
function grd_OnAcceptAllChanges(controlId) { var grd = ISGetObject(controlId); var DelChanges = grd.GetChanges("Deleted"); for (var i in DelChanges) { if (DelChanges[i].Row.GetCell("Dependencies").Value != "0") { DelChanges[i].Row.UndoChanges(); } } return true; }
What exactly do you want to achieve? If you want to UndoChanges, you can also validate at OnUndoChanges event. There should be a parameter, rowObject. rowObject has a properties, _RowStateCached which will able you to know if its state deleted, modified or etc. Hope this helps.
The user should not be able to delete some rows.
I will check this before the data is sent to the database. Has User deleted a row which has Dependencies (e.g. foreign key constraint), I will undo changes (for this row only).
With ClientSideEvent "OnBeforeDelete" I could inform User by realtime. But this Event is not fired in Batch Update mode. Therefore, I inform the user on OnAcceptAllChanges Event.
If you can get cells information of a row object, would it be a help for your scenario?
e.g. rowObject.GetCells()[i];
You can get the value of each cells and also keyValue in each rowObject. Hope this helps.
Hi James
I want refresh date before I check Dependencies. I have add grd.Refresh()
Now I get sometimes following Message:
Please wait while WebGrid is in progress processing request...
Is refresh performed asynchronously? Is there a way to refresh data first?
function grd_OnAcceptAllChanges(controlId) { var grd = ISGetObject(controlId); grd.Refresh(); var DelChanges = grd.GetChanges("Deleted"); for (var i in DelChanges) { if (DelChanges[i].Row.GetCell("Dependencies").Value != "0") { DelChanges[i].Row.UndoChanges(); alert("Row can't be deleted: " + DelChanges[i].Row.GetCell("Name").Value); } } return true; }
Yes, Refresh is an asynchronous AJAX process. But you can also run it synchronously by simply setting the Asynchronous property to false.
Here's how:
grid.XmlHttp.Asynchronous = false;
Remember to set it to true again after your Refresh() method call.
Hope this helps,James.
Great
Thanks James!
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname