Problem with refresh after delegate event fires. c# and asp.net.

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

George K

this code is in the aspx page and involves binding to an ASP ImageButton. I
know it's the c# code but it's still behind an ASP page
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top