G
George K
Hi, i have a very irriting problem that i have written a short piece of code
to demonstrate. The problem is that my aspx page is not fully refreshed
after an event, which is delegated to an ImageButton during runtime, is
fired. Any suggestions would be great. This code is the c# behind a webform
with 1 panel and 2 buttons on it. I can see that the Page controls are
correct after the event, but the page does not display it this way.
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Panel Panel1;
private void Page_Load(object sender, System.EventArgs e)
{
if (Session["table"] != null)
Panel1.Controls.Add((Table) Session["table"]);
else
DisplayTable(true,true);
}
private void DisplayTable(bool cell1, bool cell2)
{
Table table = new Table();
Panel1.Controls.Clear();
if (cell1)
{
table.Rows.Add(CreateCell(1));
}
if (cell2)
{
table.Rows.Add(CreateCell(2));
}
Panel1.Controls.Add(table);
Session["table"] = table;
}
private TableRow CreateCell(int cellId)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
ImageButton button = new ImageButton();
button.AlternateText = "Button"+cellId;
button.ID = "BTN"+cellId;
button.CommandName = cellId.ToString();
EventInfo eventInfo = button.GetType().GetEvent("Click");
Delegate d = Delegate.CreateDelegate(typeof(ImageClickEventHandler),
this, "NewPostbackEvent");
eventInfo.AddEventHandler(button, d);
cell.Controls.Add(button);
row.Cells.Add(cell);
return row;
}
private void NewPostbackEvent(object sender,
System.Web.UI.ImageClickEventArgs e)
{
ImageButton button = (ImageButton) sender;
if (button.CommandName == "1")
DisplayTable(false, true);
else
DisplayTable(true, false);
}
private void Button1_Click(object sender, System.EventArgs e)
{
DisplayTable(true,true);
}
private void Button2_Click(object sender, System.EventArgs e)
{
// Page.FindControl("BTN1");
// Page.FindControl("BTN2");
}
to demonstrate. The problem is that my aspx page is not fully refreshed
after an event, which is delegated to an ImageButton during runtime, is
fired. Any suggestions would be great. This code is the c# behind a webform
with 1 panel and 2 buttons on it. I can see that the Page controls are
correct after the event, but the page does not display it this way.
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Panel Panel1;
private void Page_Load(object sender, System.EventArgs e)
{
if (Session["table"] != null)
Panel1.Controls.Add((Table) Session["table"]);
else
DisplayTable(true,true);
}
private void DisplayTable(bool cell1, bool cell2)
{
Table table = new Table();
Panel1.Controls.Clear();
if (cell1)
{
table.Rows.Add(CreateCell(1));
}
if (cell2)
{
table.Rows.Add(CreateCell(2));
}
Panel1.Controls.Add(table);
Session["table"] = table;
}
private TableRow CreateCell(int cellId)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
ImageButton button = new ImageButton();
button.AlternateText = "Button"+cellId;
button.ID = "BTN"+cellId;
button.CommandName = cellId.ToString();
EventInfo eventInfo = button.GetType().GetEvent("Click");
Delegate d = Delegate.CreateDelegate(typeof(ImageClickEventHandler),
this, "NewPostbackEvent");
eventInfo.AddEventHandler(button, d);
cell.Controls.Add(button);
row.Cells.Add(cell);
return row;
}
private void NewPostbackEvent(object sender,
System.Web.UI.ImageClickEventArgs e)
{
ImageButton button = (ImageButton) sender;
if (button.CommandName == "1")
DisplayTable(false, true);
else
DisplayTable(true, false);
}
private void Button1_Click(object sender, System.EventArgs e)
{
DisplayTable(true,true);
}
private void Button2_Click(object sender, System.EventArgs e)
{
// Page.FindControl("BTN1");
// Page.FindControl("BTN2");
}