Events not triggered for dynamic buttons placed inside the spread control

Posted by: jonathanlau2828 on 2 April 2019, 5:39 pm EST

  • Posted 2 April 2019, 5:39 pm EST

    Hi,

    We are referring following link for setting a button cell dynamically.

    http://helpcentral.componentone.com/NetHelp/SpreadNet7/ASP2/spweb-setbuttoncell.html

    We could add the button to the cell but the events are not getting triggered. Attached the sample code which is used for our testing.

    test.zip

    Regards,
    Kamal
  • Replied 4 April 2019, 4:44 pm EST

    Hi Kamal,
    The issue is because you have added the ButtonCommand EventHandler within the !Page.IsPostBack. Please add handler outside this condition, the issue should be resolved.
    Please refer to the following code snippet for reference.

     protected void Page_Load(object sender, EventArgs e)
    {
    FpSpread1.ButtonCommand += new SpreadCommandEventHandler(this.FpSpread1_ButtonCommand1);
    if (!Page.IsPostBack)
    {
    FpSpread1.ActiveSheetView.RowCount = 3;

    FpSpread1.ActiveSheetView.Cells[0, 0].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.PushButton, "Click");
    FpSpread1.ActiveSheetView.Cells[1, 1].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.ImageButton, "images/addtocart.gif");
    FpSpread1.ActiveSheetView.Cells[2, 2].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.LinkButton, "www.fpoint.com");

    }
    }

    You may also add event handler from the aspx page instead of CodeBehind.

    Regards,
    Manish Gupta
  • Replied 26 April 2019, 1:01 am EST

    Hi,

    We have a Spread sheet list with multiple rows and each row has one check box in first cell and buttons in 2nd and 3rd cells. We want to the check box event should get fired when the Check box is checked and the button events should fire only button is clicked. Currently, the button event is triggered even when the checkbox is checked and also when the button is clicked. How do we prevent this?


    protected void Page_Load(object sender, EventArgs e)
    {
    // checkbox
    fpsStrategyList.CellClick += new SpreadCommandEventHandler(this.fpsStrategyListCellClick);
    // Button
    fpsStrategyList.ButtonCommand += new SpreadCommandEventHandler(this.fpsStrategyListFourmulaViewClick);
    }


    //checkbox Event method

    protected void fpsStrategyListCellClick (object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
    {
    int rowindex = Convert.ToInt32(fpsStrategyList.ActiveSheetView.Rows[0].Index);
    }


    //Button Event Method

    protected void fpsStrategyListFourmulaViewClick(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
    {
    int rowindex = Convert.ToInt32(fpsStrategyList.ActiveSheetView.Rows[0].Index);
    }

    Regards,
    Kamal
  • Marked as Answer

    Replied 29 April 2019, 12:46 am EST

    Hi Kamal,
    We are sorry, the CheckBox click can also be handled by using ButtonCommand event. You may add condition check to detect if the event is raised because of the Button or CheckBox.

    However, we have created an enhancement request for the same. We will share the request id soon.

    As you said, each row's first cell contains CheckBox, you may use the following code snippet:
    protected void Page_Load(object sender, EventArgs e)
    {
    FpSpread1.ButtonCommand += FpSpread1_ButtonCommand;
    if (!IsPostBack)
    {
    FpSpread1.ActiveSheetView.RowCount = 3;
    CheckBoxCellType cell= new FarPoint.Web.Spread.CheckBoxCellType();
    cell.AutoPostBack = true;
    cell.Text = "Some text";
    FpSpread1.ActiveSheetView.Cells[0, 0].CellType = cell;
    FpSpread1.ActiveSheetView.Cells[1, 1].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.ImageButton, "images/addtocart.gif");
    FpSpread1.ActiveSheetView.Cells[2, 2].CellType = new FarPoint.Web.Spread.ButtonCellType("OneCommand", FarPoint.Web.Spread.ButtonType.LinkButton, "www.fpoint.com");
    }
    }
    private void FpSpread1_ButtonCommand(object sender, SpreadCommandEventArgs e)
    { // first column containg checkbox
    if (((System.Drawing.Point)e.CommandArgument).Y == 0)
    {
    // code for checkbox click
    }else{
    // code for Button Click
    }
    }
    }


    Hope it helps!

    Regards,
    Manish Gupta
  • Replied 29 April 2019, 2:19 pm EST

    Hi Kamal,
    This request has been forwarded with internal tracking id 272132.

    Regards,
    Manish Gupta
  • Replied 29 April 2019, 7:11 pm EST

    Thanks Manish. Your solution helped.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels