470,647 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

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

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(ImageClickEventHand ler),
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");
}
Jul 19 '05 #1
4 8289
This doesn't involve ASP...

"George K" <ge*******@bluefiretechnologies.com> wrote in message
news:gv*******************@wards.force9.net...
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(ImageClickEventHand ler),
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");
}

Jul 19 '05 #2

"George K" <ge*******@bluefiretechnologies.com> wrote in message
news:gv*******************@wards.force9.net...
This code is the c# behind a webform


http://www.aspfaq.com/5002

Ray at work
Jul 19 '05 #3
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

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...

"George K" <ge*******@bluefiretechnologies.com> wrote in message
news:gv*******************@wards.force9.net...
This code is the c# behind a webform


http://www.aspfaq.com/5002

Ray at work

Jul 19 '05 #4
George K wrote:
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

You're still more likely to get help for this on a dotnet newsgroup. We're
not telling you this to chastise you: we're merely trying to help you get
the help you need. Oh wait! you crossposted this to a dotnet newsgroup! OK,
you should be all set.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James | last post: by
1 post views Thread by ppatel | last post: by
1 post views Thread by Kirill Osipov | last post: by
1 post views Thread by JohnJohn | last post: by
6 posts views Thread by ffa | last post: by
9 posts views Thread by raylopez99 | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.