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 is fired, which
is delegated to an ImageButton during runtime. 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.W ebControls.Butt on
Button1;
protected System.Web.UI.W ebControls.Butt on
Button2;
protected System.Web.UI.W ebControls.Pane l
Panel1;
private void Page_Load(objec t sender,
System.EventArg s e)
{
if (Session["table"] != null)
Panel1.Controls .Add
((Table) Session["table"]);
else
DisplayTable(tr ue,true);
}
private void DisplayTable(bo ol 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.Alternat eText
= "Button"+cellId ;
button.ID = "BTN"+cellI d;
button.CommandN ame =
cellId.ToString ();
EventInfo eventInfo =
button.GetType( ).GetEvent("Cli ck");
Delegate d =
Delegate.Create Delegate(typeof (ImageClickEven tHandler),
this, "NewPostbackEve nt");
eventInfo.AddEv entHandler(butt on,
d);
cell.Controls.A dd(button);
row.Cells.Add(c ell);
return row;
}
private void NewPostbackEven t(object
sender, System.Web.UI.I mageClickEventA rgs e)
{
ImageButton button = (ImageButton)
sender;
if (button.Command Name == "1")
DisplayTable(fa lse, true);
else
DisplayTable(tr ue, false);
}
private void Button1_Click(o bject sender,
System.EventArg s e)
{
DisplayTable(tr ue,true);
}
private void Button2_Click(o bject sender,
System.EventArg s e)
{
// Page.FindContro l("BTN1");
// Page.FindContro l("BTN2");
}
piece of code to demonstrate. The problem is that my aspx
page is not fully refreshed after an event is fired, which
is delegated to an ImageButton during runtime. 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.W ebControls.Butt on
Button1;
protected System.Web.UI.W ebControls.Butt on
Button2;
protected System.Web.UI.W ebControls.Pane l
Panel1;
private void Page_Load(objec t sender,
System.EventArg s e)
{
if (Session["table"] != null)
Panel1.Controls .Add
((Table) Session["table"]);
else
DisplayTable(tr ue,true);
}
private void DisplayTable(bo ol 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.Alternat eText
= "Button"+cellId ;
button.ID = "BTN"+cellI d;
button.CommandN ame =
cellId.ToString ();
EventInfo eventInfo =
button.GetType( ).GetEvent("Cli ck");
Delegate d =
Delegate.Create Delegate(typeof (ImageClickEven tHandler),
this, "NewPostbackEve nt");
eventInfo.AddEv entHandler(butt on,
d);
cell.Controls.A dd(button);
row.Cells.Add(c ell);
return row;
}
private void NewPostbackEven t(object
sender, System.Web.UI.I mageClickEventA rgs e)
{
ImageButton button = (ImageButton)
sender;
if (button.Command Name == "1")
DisplayTable(fa lse, true);
else
DisplayTable(tr ue, false);
}
private void Button1_Click(o bject sender,
System.EventArg s e)
{
DisplayTable(tr ue,true);
}
private void Button2_Click(o bject sender,
System.EventArg s e)
{
// Page.FindContro l("BTN1");
// Page.FindContro l("BTN2");
}