Free Support Forum - aspose.com

Webcontrol

Hi,

I'm trying to build a web control that used the gridweb.
The process is straigh foward, but I have difficulty to see how it goes with the gridweb.
I've tried many configuration, but none seems to trigger the submit and save event handler.
How should this be correctly be done?

The simple example attach illustrate my hard time creating a simple webcontrol.
In the same time, can you please point me, how the data in the grid is saved between event? (this is highligh in the event method)

Hi,

Thanks for the project.

We will check and get back back to you soon.

Thank you.

Hi,

1. Your web control should Implement INamingContainer interface.

2. You should set an ID for the embeded GridWeb control.

3. When you create your web control in thr form , you also need to set an ID for the control.

I have modified the code for you:

[WebCustomControl1.cs]

using System;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Grid.Web;
using Aspose.Grid.Web.Data;

namespace testwebcontrol
{

public class WebCustomControl1 : WebControl, INamingContainer
{
private GridWeb grid;
private WebWorksheet sheet;

// You need not to override the RenderContents method, so remove it.

protected override void CreateChildControls()
{
base.CreateChildControls();

grid = new GridWeb();
grid.ID = "InnerGrid";
grid.WebWorksheets.Add();
sheet = grid.WebWorksheets[0];
sheet.Cells["A1"].PutValue("initial value");
sheet.Cells["A2"].PutValue("value 000");
grid.SubmitCommand += new WorkbookEventHandler(grid_SubmitCommand);
grid.SaveCommand += new WorkbookEventHandler(grid_SaveCommand);
Controls.Add(grid);

}

void grid_SubmitCommand(object sender, EventArgs e)
{
sheet = grid.WebWorksheets[0];
sheet.Cells.Clear();
sheet.Cells["A1"].PutValue("toggled value");
sheet.Cells["A2"].PutValue("value 111");
}

void grid_SaveCommand(object sender, EventArgs e)
{
sheet = grid.WebWorksheets[0];
sheet.Cells["A1"].PutValue("final value (should be 'value 111', if click submit then save)");
sheet.Cells["A2"].PutValue(sheet.Cells["A2"].Value);
}
}
}

[test.aspx.cs]

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using testwebcontrol;

public class test : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlForm form;

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
WebCustomControl1 ctrl = new WebCustomControl1();
ctrl.ID = "Grid1";
form.Controls.Add(ctrl);
}
}

Thank you very much.
Great service as always.
It works perfectly.