473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Setting event handler during PostBackEvent

Hello all,

Why can't I wire up an event during the "Raise PostBackEvent" stage of a
postback?

Just in case this is the wrong question, the situation:

deep in the bowls of some code-behind loop:

ImageButton A is created (with ID "A"). ImageButton A's click event is
wired to EventHandler E.

When the user clicks the button, page posts back, page_load runs, event
fires all is good with the world.

During Event E,however, I want to run through aforementioned loop again,
re-creating ImageButton A and assigning its click event to Event E
(again) which seems to work just fine. In fact, all my image buttons
re-appear on the page just like I would expect.

The problem happens when the user clicks on the newly created
ImageButton. The page posts back, page_load fires, but Event E is never
raised.

I'm sure this is by design, but I'm not sure I follow. Don't event
assignments make the round trip in the state bag? I would think that,
as long as I wire everything up before SaveViewState/Render, that ALL
object properties would be saved.

Whate have I missed?

Russell

Nov 19 '05 #1
5 1688
If I understand you correctly,you are _adding_ a _new_ imagebutton in
the eventhandler. You should be aware of the fact that you always add a
control for the _current request_ only. That means that you have to
take into account that you _readd_ the control upon every postback, if
you want to be able to handle its events/keep a valid viewstate/etc.

Nov 19 '05 #2
Hi,

if I understood correct what you mean, then basically page framework has
already in that stage determined which controls will raise which events
(postback event, data changed events), and this detection happens just
before Page_load and second time, right after Page_Load (for dynamical
controls added in Page_Load), but before any postback events (as those
events are raised acording to prementioned detection).

So in other words the controls that raises events should be in Controls
collection at page_Load at the latest. Is this the case with your
ImageButtons?

And to reply about ViewState, basically even wiring don't get saved there,
but they need to be done on every request (unless you of course use
declarative syntax and wire events there when compiler manmages this such
that event handlers are always wired)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Russell Smallwood" <ru******@themaplegroup.com> wrote in message
news:MP************************@news.giganews.com. ..
Hello all,

Why can't I wire up an event during the "Raise PostBackEvent" stage of a
postback?

Just in case this is the wrong question, the situation:

deep in the bowls of some code-behind loop:

ImageButton A is created (with ID "A"). ImageButton A's click event is
wired to EventHandler E.

When the user clicks the button, page posts back, page_load runs, event
fires all is good with the world.

During Event E,however, I want to run through aforementioned loop again,
re-creating ImageButton A and assigning its click event to Event E
(again) which seems to work just fine. In fact, all my image buttons
re-appear on the page just like I would expect.

The problem happens when the user clicks on the newly created
ImageButton. The page posts back, page_load fires, but Event E is never
raised.

I'm sure this is by design, but I'm not sure I follow. Don't event
assignments make the round trip in the state bag? I would think that,
as long as I wire everything up before SaveViewState/Render, that ALL
object properties would be saved.

Whate have I missed?

Russell

Nov 19 '05 #3
In article <eS**************@TK2MSFTNGP12.phx.gbl>,
jo****@aspalliance.com says...
Hi,

if I understood correct what you mean, then basically page framework has
already in that stage determined which controls will raise which events
(postback event, data changed events), and this detection happens just
before Page_load and second time, right after Page_Load (for dynamical
controls added in Page_Load), but before any postback events (as those
events are raised acording to prementioned detection).

So in other words the controls that raises events should be in Controls
collection at page_Load at the latest. Is this the case with your
ImageButtons?

And to reply about ViewState, basically even wiring don't get saved there,
but they need to be done on every request (unless you of course use
declarative syntax and wire events there when compiler manmages this such
that event handlers are always wired)


Here's the sequence:

Initial Request:

Page_Init (don't care about this at this point)

Page_Load(load my controls including initial set of buttons)

Event Handling (don't care at this point)
Works great Users pushes button and....

2nd Trip

Page_Init(event handlers are wired up)

Page_Load(page is drawn with old buttons)

EventHandling (old buttons are replaced with new buttons and event
delegates are set)
Works great, new buttons appear on the web form and cause postback no
problem. User pushes new buttons and....
3rd Trip

Page_Init(event handlers are wired up - WRONG - despite the fact that
the buttons were added to the controls container on that LAST trip
before the page was rendered, and are renedered properly in the response
stream, the event handler doesn't appear to be connected with the
control)

Page_Load(page is drawn with last set of buttons - This is what I expect
and want)

Event Handling(event handler never fires even thought the button is
pressed on the user's end and causes postback)

</EXAMPLE>

Why? Everything else about the image button get set correctly, the
image, the id, other attributes everything EXECEPT the event handler
property.

Nov 19 '05 #4
In article <11*********************@l41g2000cwc.googlegroups. com>,
wi****@gmail.com says...
If I understand you correctly,you are _adding_ a _new_ imagebutton in
the eventhandler. You should be aware of the fact that you always add a
control for the _current request_ only. That means that you have to
take into account that you _readd_ the control upon every postback, if
you want to be able to handle its events/keep a valid viewstate/etc.


Thank you for your time and reply. I tried clarifying the situation in
a follow-up to another response to my querey. I says:

Here's the sequence:

Initial Request:

Page_Init (don't care about this at this point)

Page_Load(load my controls including initial set of buttons)

Event Handling (don't care at this point)
Works great Users pushes button and....

2nd Trip

Page_Init(event handlers are wired up)

Page_Load(page is drawn with OLD buttons - This is expected)

EventHandling (old buttons are replaced with new buttons and event
delegates are set)
Works great, new buttons appear on the web form and cause postback no
problem. User pushes new buttons and....
3rd Trip

Page_Init(event handlers are wired up - WRONG - despite the fact that
the buttons were added to the controls container on that LAST trip
before the page was rendered, and are renedered properly in the response
stream, the event handler doesn't appear to be connected with the
control)

Page_Load(page is drawn with last set of buttons - This is what I expect
and want)

Event Handling(event handler never fires even thought the button is
pressed on the user's end and causes postback)

</EXAMPLE>

Why? Everything else about the image button get set correctly, the
image, the id, other attributes everything EXECEPT the event handler
property.

Nov 19 '05 #5
In article <MP************************@news.giganews.com>,
ru******@themaplegroup.com says...
Just in case anyone is following this thread here's some closure:

The problem had nothing to do with Page lifecyle and more to do with
control identification.

In my laziness, I was letting the rendering engine autoID my controls
and, for some reason the first time it rendered my ImageButton (the one
i added in the evernt handler for another control) it was giving it an
ID that didn't match the ID corresponding to the event handler (why... I
don't know). The second time around, it would be assigned the proper ID
and hence the on-again off-again problem I was experiencing.

I discovered all this by turning on the page trace and watching the
controls tree values and the PostBack data.

I went back and made sure to give ID's to all the controls in the
control tree that parented my buttons and everything worked perfectly.

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
5
by: Flare | last post by:
(ASP.NET 1.1) Hi I have a problem with my ViewStates in a userControl. The problem is that the ViewState is not "writte" og changed if you like after editing in my case a textbox. This is...
3
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not...
2
by: John Dalberg | last post by:
I need to know what happens after Page_load has finished so I put a breakpoint at the last statement. However after stepping into after this last statement, the app continues running without the...
1
by: David Veeneman | last post by:
I am writing a control that relies on its host to validate the contents of one of its fields. The control fires a custom 'FooNeedsValidating' event and passes the field's data with the event. The...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
by: kaczmar2 | last post by:
I have an ASP.NET page where controls are created dynamically, and I have an issue where one event handler creates another set of controls, and then adds event handlers to those controls. The...
2
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.