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

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

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

    Foo Man Chew Guest

  4. #3

    Default 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...
    > This code is the c# behind a webform
    [url]http://www.aspfaq.com/5002[/url]

    Ray at work


    Ray at Guest

  5. #4

    Default 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

  6. #5

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

    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"


    Bob Barrows Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139