Clicking the Cancel button causes the Insert Routine to fire if in Add(row) is run first and a value exists

  • ccooper FP 3 years, 1 month ago

    Clicking the Cancel button causes the Insert Routine to fire if in Add(row) is run first and a value exists.  I simply am trying to cancel, but if anything was input during the addRow it tries to run the Insert before the cancel which I do not need it to do.  I simply want to cancel.  I also notice if I update a hundred items in the grid and click "Cancel", it tries to run the update command 100 times.  Why would it attempt to do either the insert or the update if I am simply trying to press cancel?

  • ccooper FP 3 years, 1 month ago

    This is the code in the Render:

    Dim cancelBtn As Control = fpMeterManufacturers.FindControl("Cancel")

    If Not cancelBtn Is Nothing Then

    CType(cancelBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT $().ready(function() {" & fpMeterManufacturers.ClientID & ".CallBack(""CancelCommand"");return false; });")

    End If

     

    Private

    Sub fpMeterManufacturers_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles fpMeterManufacturers.ButtonCommand

    If

    e.CommandName = "CancelCommand" Then

    addAddScript =

    "CANCEL_SCRIPT"

    'Do whatever is needed

    End If

  • -1p
    Subodh Sinha-1p 3 years, 1 month ago

    Hello,

    I was not able to replicate the issue at my end. I tried with the same code. I have with the following steps:

    1. Run the project. When clicked on add row, Fpspread1_insertCommand is fired.

    2. Edited some value in the new row. Clicked on Cancel button. This time FpSpread1_ButtonCommand is fired.

    Therefore, I would request you to provide a sample which replicates the issue so that I can test it at my end.

     Thanks,

    Subodh,

    Grapecity, FarPoint

  • ccooper FP 3 years, 1 month ago

    It works as expected if I do not enter a value into the added row, but the minute I enter a value and hit cancel then it always runs the insert_command before it running the cancel functionality. 

     

    <

    FarPoint:FpSpread ID="fpMeterManufacturers"

    runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="430px"

    Width="970px" EnableAjaxCall="true" EnableViewState="true" >

    <

    TitleInfo BackColor="#E7EFF7″ ForeColor="" HorizontalAlign="Center" VerticalAlign="NotSet" Font-Size="X-Large"></TitleInfo>

    <CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"

    ButtonShadowColor="ControlDark">

    <Background BackgroundImageUrl="SPREADCLIENTPATH:/img/cbbg.gif"></Background>

    </CommandBar>

    <Sheets>

    <FarPoint:SheetView SheetName="Edit" AutoGenerateColumns="false" AutoPostBack="false" >

    </FarPoint:SheetView>

    </Sheets>

    </FarPoint:FpSpread>

    <script type="text/javascript"> 

    $().ready(function() {

    var ss = document.getElementById('<%=fpMeterManufacturers.ClientID %>’);

    if (document.all) {

    ss.onCallBackStart = DoOnCallBackStart;

    ss.onCallBackStopped = DoOnCallBackStopped;

    } else {

    ss.addEventListener("CallBackStart", DoOnCallBackStart, false);

    ss.addEventListener("CallBackStopped", DoOnCallBackStopped, false);

    }

    });

     

    function DoOnCallBackStart() {

    if (event == null) {

    event = window.event;

    }

    }

     

    function

    DoOnCallBackStopped() {

    //ShowClientMessage(

    'Please add your information.’);

    RunAddScript();

    }

     function

    RunAddScript() {

    var ss = document.getElementById('<%=fpMeterManufacturers.ClientID %>’);

    if (ss.readyState == "complete") {

    ss.Add();

    ss.SetSelectedRange(ss.GetRowCount() – 1, -1, 1, -1);

    ss.ScrollTo(ss.GetRowCount() – 1, 0);

    var selectedVal = $('#<%=ddlEditType.ClientID %>’).val();

    if (selectedVal == 'SCALC’) {

    ss.SetActiveCell(ss.GetRowCount() – 1, 0);

    }

    else {

    ss.SetActiveCell(ss.GetRowCount() – 1, 1);

    }

    }

    else {

    setTimeout(RunAddScript, 10);

    }

    }

     

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    Dim updateBtn As Control = fpMeterManufacturers.FindControl("Add")

    If Not updateBtn Is Nothing Then

    'CTYPE(updateBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT" & fpMeterManufacturers.ClientID & ".Add();" & ClientScript.GetPostBackEventReference(fpMeterManufacturers, "New Row") & ";return false; ")

    CType(updateBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT $().ready(function() {" & fpMeterManufacturers.ClientID & ".CallBack(""AddCommand"");return false; });")

    End If

    Dim deleteBtn As Control = fpMeterManufacturers.FindControl("Delete")

    If Not deleteBtn Is Nothing Then

    CType(deleteBtn, WebControls.Image).Attributes.Add("onclick", "return ConfirmDelete();")

    End If

    Dim cancelBtn As Control = fpMeterManufacturers.FindControl("Cancel")

    If Not cancelBtn Is Nothing Then

    CType(cancelBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT $().ready(function() {" & fpMeterManufacturers.ClientID & ".CallBack(""CancelCommand"");return false; });")

    End If

     End Sub

     

    Private Sub fpMeterManufacturers_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles fpMeterManufacturers.ButtonCommand

    If e.CommandName = "AddCommand" Then

    addAddScript =

    "ADD_SCRIPT"

    fpMeterManufacturers.Cells(0, 1, fpMeterManufacturers.Rows.Count – 1, 1).Locked =

    True

    fpMeterManufacturers.Cells(0, 2, fpMeterManufacturers.Rows.Count – 1, 2).Locked =

    True

    If ddlEditType.SelectedValue = "SCALC" Then fpMeterManufacturers.Cells(0, 0, fpMeterManufacturers.Rows.Count – 1, 0).Locked = True

    ElseIf e.CommandName = "CancelCommand" Then

    addAddScript =

    "CANCEL_SCRIPT"

    fpMeterManufacturers.Cells(0, 1, fpMeterManufacturers.Rows.Count – 1, 1).Locked =

    False

    fpMeterManufacturers.Cells(0, 2, fpMeterManufacturers.Rows.Count – 1, 2).Locked =

    False

    End If

    End Sub

    Private

    Sub fpMeterManufacturers_InsertCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles fpMeterManufacturers.InsertCommand

     End Sub

     

  • ccooper FP 3 years, 1 month ago

    It works as expected if I do not enter a value into the added row, but the minute I enter a value and hit cancel then it always runs the insert_command before it running the cancel functionality. 

     

    <

    FarPoint:FpSpread ID="fpMeterManufacturers"

    runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="430px"

    Width="970px" EnableAjaxCall="true" EnableViewState="true" >

    <

    TitleInfo BackColor="#E7EFF7″ ForeColor="" HorizontalAlign="Center" VerticalAlign="NotSet" Font-Size="X-Large"></TitleInfo>

    <CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"

    ButtonShadowColor="ControlDark">

    <Background BackgroundImageUrl="SPREADCLIENTPATH:/img/cbbg.gif"></Background>

    </CommandBar>

    <Sheets>

    <FarPoint:SheetView SheetName="Edit" AutoGenerateColumns="false" AutoPostBack="false" >

    </FarPoint:SheetView>

    </Sheets>

    </FarPoint:FpSpread>

    <script type="text/javascript"> 

    $().ready(function() {

    var ss = document.getElementById('<%=fpMeterManufacturers.ClientID %>’);

    if (document.all) {

    ss.onCallBackStart = DoOnCallBackStart;

    ss.onCallBackStopped = DoOnCallBackStopped;

    } else {

    ss.addEventListener("CallBackStart", DoOnCallBackStart, false);

    ss.addEventListener("CallBackStopped", DoOnCallBackStopped, false);

    }

    });

     

    function DoOnCallBackStart() {

    if (event == null) {

    event = window.event;

    }

    }

     

    function

    DoOnCallBackStopped() {

    //ShowClientMessage(

    'Please add your information.’);

    RunAddScript();

    }

     function

    RunAddScript() {

    var ss = document.getElementById('<%=fpMeterManufacturers.ClientID %>’);

    if (ss.readyState == "complete") {

    ss.Add();

    ss.SetSelectedRange(ss.GetRowCount() – 1, -1, 1, -1);

    ss.ScrollTo(ss.GetRowCount() – 1, 0);

    var selectedVal = $('#<%=ddlEditType.ClientID %>’).val();

    if (selectedVal == 'SCALC’) {

    ss.SetActiveCell(ss.GetRowCount() – 1, 0);

    }

    else {

    ss.SetActiveCell(ss.GetRowCount() – 1, 1);

    }

    }

    else {

    setTimeout(RunAddScript, 10);

    }

    }

     

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    fpMeterManufacturers.ActiveSheetView.AutoGenerateColumns =

    False

    fpMeterManufacturers.ActiveSheetView.AutoPostBack =

    False

    fpMeterManufacturers.ActiveSheetView.Columns.Count = columnNumber

    fpMeterManufacturers.VerticalScrollBarPolicy = FarPoint.Web.Spread.ScrollBarPolicy.AsNeeded

    fpMeterManufacturers.ActiveSheetView.AllowPage =

    False

    fpMeterManufacturers.ActiveSheetView.AllowSort =

    True

    fpMeterManufacturers.ActiveSheetView.AllowDelete =

    True

    fpMeterManufacturers.ActiveSheetView.AllowInsert =

    True

    fpMeterManufacturers.ActiveSheetView.Protect =

    True

    fpMeterManufacturers.ActiveSheetView.SheetName = nameVal

    Dim updateBtn As Control = fpMeterManufacturers.FindControl("Add")

    If Not updateBtn Is Nothing Then

    'CTYPE(updateBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT" & fpMeterManufacturers.ClientID & ".Add();" & ClientScript.GetPostBackEventReference(fpMeterManufacturers, "New Row") & ";return false; ")

    CType(updateBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT $().ready(function() {" & fpMeterManufacturers.ClientID & ".CallBack(""AddCommand"");return false; });")

    End If

    Dim deleteBtn As Control = fpMeterManufacturers.FindControl("Delete")

    If Not deleteBtn Is Nothing Then

    CType(deleteBtn, WebControls.Image).Attributes.Add("onclick", "return ConfirmDelete();")

    End If

    Dim cancelBtn As Control = fpMeterManufacturers.FindControl("Cancel")

    If Not cancelBtn Is Nothing Then

    CType(cancelBtn, WebControls.Image).Attributes.Add("onclick", "BLOCKED SCRIPT $().ready(function() {" & fpMeterManufacturers.ClientID & ".CallBack(""CancelCommand"");return false; });")

    End If

     End Sub

     

    Private Sub fpMeterManufacturers_ButtonCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles fpMeterManufacturers.ButtonCommand

    If e.CommandName = "AddCommand" Then

    addAddScript =

    "ADD_SCRIPT"

    fpMeterManufacturers.Cells(0, 1, fpMeterManufacturers.Rows.Count – 1, 1).Locked =

    True

    fpMeterManufacturers.Cells(0, 2, fpMeterManufacturers.Rows.Count – 1, 2).Locked =

    True

    If ddlEditType.SelectedValue = "SCALC" Then fpMeterManufacturers.Cells(0, 0, fpMeterManufacturers.Rows.Count – 1, 0).Locked = True

    ElseIf e.CommandName = "CancelCommand" Then

    addAddScript =

    "CANCEL_SCRIPT"

    fpMeterManufacturers.Cells(0, 1, fpMeterManufacturers.Rows.Count – 1, 1).Locked =

    False

    fpMeterManufacturers.Cells(0, 2, fpMeterManufacturers.Rows.Count – 1, 2).Locked =

    False

    End If

    End Sub

    Private

    Sub fpMeterManufacturers_InsertCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles fpMeterManufacturers.InsertCommand

     End Sub

     

  • ccooper FP 3 years, 1 month ago

    I found that the fix to this is to run the cancel command first in the onclick event before running the callback functionality.  This is the line of code that I changed to in the Pre-Render to get it to work as expected:

    Dim

    cancelBtn As Control = fpMeterManufacturers.FindControl("Cancel")

    If Not cancelBtn Is Nothing Then

    CType(cancelBtn, WebControls.Image).Attributes.Add("onclick", fpMeterManufacturers.ClientID & ".Cancel();" & fpMeterManufacturers.ClientID & ".CallBack(""CancelCommand"");return false;")

    End If

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.