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);
}
}