Hello
I need to generate a postback when exit of a cell in RowAdding. I achieved something like this, with event RowUpdating. I did, in page aspx:
<asp:UpdatePanel runat="server" ID="SampleUpdatePanel"><ContentTemplate>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyFields="OrderID" OnRowUpdating="WebDataGrid1_RowUpdating">
.
<Behaviors> <ig:Activation> </ig:Activation> <ig:EditingCore AutoCRUD="False"> <Behaviors> <ig:CellEditing> <CellEditingClientEvents ExitedEditMode="WebDataGrid1_CellEditing_ExitedEditMode" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors></Behaviors>
</ig:WebDataGrid>
</ContentTemplate></asp:UpdatePanel>
<script type="text/javascript">function WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs) {
__doPostBack('<%= SampleUpdatePanel.ClientID %>', '');}
</script>
Therefore, with this, it generates a postback every time it exits to edit a cell (any cell, not necessarily the whole row) and enters in the following event:
protected void WebDataGrid1_RowUpdating(object sender, RowUpdatingEventArgs e){
//My code
}
This is okay, because it's just what I need.
Now, I need to make the same, but in this case, in a RowAdding event. I did something like this, in page aspx:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyFields="OrderID" OnRowUpdating="WebDataGrid1_RowUpdating" OnRowAdding="WebDataGrid1_RowAdding">
<Behaviors>
<ig:Activation> </ig:Activation> <ig:EditingCore AutoCRUD="False"> <Behaviors> <ig:CellEditing> <CellEditingClientEvents ExitedEditMode="WebDataGrid1_CellEditing_ExitedEditMode" /> </ig:CellEditing> <ig:RowAdding> <AddNewRowClientEvents ExitedEditMode="WebDataGrid1_RowAdding_ExitedEditMode" /> </ig:RowAdding> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors></Behaviors>
function WebDataGrid1_RowAdding_ExitedEditMode(sender, eventArgs) { __doPostBack('<%= SampleUpdatePanel.ClientID %>', ''); }
But, in this case, it generates a postback (I know it because put a breakpoint in Page_Load()) every time it exits of a cell (in The last row is used to insert or add), that's ok, but NOT enters in the following event:
protected void WebDataGrid1_RowAdding(object sender, RowAddingEventArgs e){//My code}
I need to enter into this event each time it leaves of a cell (not whole row) within the row to add (in The last row is used to insert or add). What is happened? Why in this case, not enter in the event WebDataGrid1_RowAdding()?Can you help me, please? Any suggestions?
Thanks.Geovanny Domínguez
Hello Geovanny Dominguez,
Thank you for contacting Infragistics.
What I can suggest for your scenario is adding the row programatically in RowAdding_ExitedEditMode handler. This will cause a postback itself and calling __doPostBack function would not be necessary. This can be done as following:
function WebDataGrid1_RowAdding_ExitedEditMode(sender, eventArgs) { var row = eventArgs.getCell().get_row(); var itemArray = new Array(); for (var i = 0; i < row.get_cellCount; i++) { itemArray[i] = row.get_cellCount(); } sender.get_rows().add(itemArray); }
function WebDataGrid1_RowAdding_ExitedEditMode(sender, eventArgs)
{
var row = eventArgs.getCell().get_row();
var itemArray = new Array();
for (var i = 0; i < row.get_cellCount; i++) {
itemArray[i] = row.get_cellCount();
sender.get_rows().add(itemArray);
Feel free to contact me if you have any additional questions concerning this matter.
Hello Vasya
At this point, all is fine, but now I need to validate in client-side if one cell was modified or not, in this way to prevent a postback in event fired after a cell has exited edit mode. I need to trigger a postback only when a cell was modified.
Could you help me, please?
I hope your response.
Thanks.
Geovanny Domínguez.
Hello Geovanny,
What I can suggest for your scenario is defining a global variable to use it as a flag for any changes made in the cell. Afterwards in the CellValueChanged handler set the value of the flag depending on whether any changes are made and finally in ExitingEditMode to check the value of the flag and do postback if necessary as such:
var changes; function WebDataGrid1_Editing_CellValueChanged(sender, eventArgs) { var oldValue = eventArgs.get_oldValue(); var newValue = eventArgs.get_cell().get_text(); if (oldValue === newValue) { changes =false; } else { changes =true; } } function WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs) { if (changes) { __doPostBack('<%= SampleUpdatePanel.ClientID %>', ''); } }
var changes;
function WebDataGrid1_Editing_CellValueChanged(sender, eventArgs)
var oldValue = eventArgs.get_oldValue();
var newValue = eventArgs.get_cell().get_text();
if (oldValue === newValue) {
changes =false;
else {
changes =true;
function
WebDataGrid1_CellEditing_ExitedEditMode(sender, eventArgs)
if (changes) {
__doPostBack('<%= SampleUpdatePanel.ClientID %>', '');
Hope this helped. Do not hesitate to contact me if you have any additional questions regarding this matter.
I am still following your case. Have you been able to resolve the issue? If you still have any questions or concerns I will be glad to help. Do not hesitate to ask if you need any additional assistance.
Hello Vasya,
Just one more thing, please!. Now, I would like to do the same, but in the cells of row adding. Because, your suggest works perfect in the others cells, but doesn't in cells of row adding. May you help me?
After you made change to any of the values the “changes” variable is set to “true” and it remains “true” on every other cell exiting edit mode (this is the result when I test the sample).
In the sample that is attached this can be observed by putting watch on “changes” variable.
Because this variable remains true “__doPostBack” is executed every time when cell exits edit mode.
In the date time column (“Year”) when the code for setting “changes” variable is removed the Postback is not executed if you move to the cell from the same row but is executed when you move to the different row. This is caused by the changed date time in the date code. For this column DateTime.Now is used to generate cell’s values and if you put breakpoint in “RowUpdating” event you will see that it is fired and date/time in e.Values is different than date/time in e.OldValues.
Hello Alex,
Thanks for reply. In previous posts I explained that this is always happening on any cells after them have been modified. I attach the sample project, Please test this on your PC, select the first option in the DropDownList then clic on the button. First, you can enter and then exit edit mode in any cell (excluding the cells in the Year column) and you can watch that does not execute any postback to server side (this is okay, bacause "changes" is false). Second, you can edit any cell and afterwards again repeat the first step, and you'll watch the WebDataGrid will always execute a postback (this is wrong because "changes" remains false).
Not only in Year column, moreover Year column is an exception, because , you can comment all code lines script js and ClientEvents in Default.aspx.cs, and in the Year column continues occurring this issue.
Then, your review is not so true!
I think that is the EditorProvider...Let me know if you understood me and were be able to reproduce the issue.
Geovanny Domínguez
Entering and then exiting edit mode in “Year” column causes Postback because in “GridViewData_Editing_CellValueChanged” there is some code executed which leads to assigning “true” for the “changes” variable. This leads to __doPostback() execution in “GridViewData_CellEditing_ExitedEditMode”.
This is caused by the following comparison which fails because “oldValue” is different than “newValue” even if you are not changing it:
if (oldValue == newValue) {
changes = false;
changes = true;
If you observe the following variables you will notice that they are different because in the first old value is returned and in the second the text of the cell:
var oldValue = eventArgs.get_oldValue(); // returns Tue Mar 5 10:02:21 UTC+0200 2013
var newValue = eventArgs.get_cell().get_text(); // returns "3/5/2013"
If you want to make such evaluation you should first format the old value appropriately:
eventArgs.get_oldValue().format("M/d/yyyy");
In this way “changes” will be set to false and no Postback will be executed.
Thanks for your reply. I understand what my project is doing! I explain again. I want to know, why the WebDataGrid is doing a postback every time I pass a cell (enter and exit the edit mode) of the YEAR column without making any change.
Then you can edit one cell and afterwards you will watch when you do to click on any cell and exit ot this (without making changes), the WebDataGrid will always execute a postback.
If I do not make changes, "changes" variable is false and it should doesn't run a postback, but after making an edition the WebDataGrid always executes a postback.
Thanks!
The mentioned by you method has the following code in it:
function GridViewData_CellEditing_ExitedEditMode(webDataGrid, eventArgs) {
//to check the value of the flag and do postback if necessary
__doPostBack('<%= UpdatePanelMaster.ClientID %>', '');
//webDataGrid.get_behaviors().get_editingCore()._commitUpdates();
Since “changes” is always false when no modifications are made in the cell there is no Postback to the Server. When modification is made there is a Postback executed.
What is the actual behavior that you observe and what you expect to happen when this function is called?
Regarding calendar issue if I comment the following lines and load all components initially the calendar is displayed correctly:
protected void Page_Load(object sender, EventArgs e)
// Control obj = GetPostBackControl(this.Page);
// if (IsPostBack && obj == null) //obj será null con algun evento que se produzca en la WebDataGrid (por ejm luego de editar una celda)
loadDynamicGrid();
If you comment the “UpdatePanel” the calendar is shown correctly too.
Some of the components need to be loaded initially in order to function correctly. If you add them too late or by Async Postback such issues may occur.