Ask a Question related to ASP Database, Design and Development.
-
George K #1
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");
}
George K Guest
-
Event Fires after CreateChildControls
I have created a C# control that creates its objects within CreateChildControls. One of those objects is a button which I have attached to a... -
Dropdownlist onselectedIndexChanged event not fires
Hi All, I have 22 years of over all experience in programming but just recently started to learn WEB applications, and started to write my... -
user control in a datagrid does not work with a delegate and event
Hi, I have a user control that raises an event which works perfectly outside a datagrid. But trying to do this within a datagrid causes some... -
ItemCommand Event fires twice
Hi! I have a DataList with some linkbuttons, and when i click them the eventhandler fires twice. Is there a way around this?, it's the same... -
Page Load Event Fires Twice
This is a classic asp newsgroup. While you may be lucky enough to find a dotnet-savvy person here who can answer your question, you can eliminate... -
Foo Man Chew #2
Re: Problem with refresh after delegate event fires. c# and asp.net.
This doesn't involve ASP...
"George K" <georgekaz@bluefiretechnologies.com> wrote in message
news:gvvwb.12644$lm1.94489@wards.force9.net...code> Hi, i have a very irriting problem that i have written a short piece ofwebform> 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> 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");
> }
>
>
Foo Man Chew Guest
-
Ray at #3
Re: Problem with refresh after delegate event fires. c# and asp.net.
"George K" <georgekaz@bluefiretechnologies.com> wrote in message
news:gvvwb.12644$lm1.94489@wards.force9.net...
[url]http://www.aspfaq.com/5002[/url]> This code is the c# behind a webform
Ray at work
Ray at Guest
-
George K #4
Re: Problem with refresh after delegate event fires. c# and asp.net.
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:usoYqrtsDHA.1876@TK2MSFTNGP09.phx.gbl...>
> "George K" <georgekaz@bluefiretechnologies.com> wrote in message
> news:gvvwb.12644$lm1.94489@wards.force9.net...
>>> > This code is the c# behind a webform
> [url]http://www.aspfaq.com/5002[/url]
>
> Ray at work
>
>
George K Guest
-
Bob Barrows #5
Re: Problem with refresh after delegate event fires. c# and asp.net.
George K wrote:
You're still more likely to get help for this on a dotnet newsgroup. We're> 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
>
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"
Bob Barrows Guest



Reply With Quote

