Event Confusion
-
I sure could use some help. I have a web app with frames. I want to be able to notify frame2 when something takes place in frame1. Should be simple, but maybe I'm the simple one. I've got the event structure working because I can fire an event in frame 1 and receive and act upon it in frame 1. But when I fire it in frame 1 and try to handle it in frame 2, it is apparently never received. The event appears to fire fine (I get no errors and see it pass the statement OK in the debugger), but the handler (which also appears to be declared correctly, since I get no compile errors) never seems to receive it. Can someone point me in the proper direction? I really appreciate it! Mike.
-
I sure could use some help. I have a web app with frames. I want to be able to notify frame2 when something takes place in frame1. Should be simple, but maybe I'm the simple one. I've got the event structure working because I can fire an event in frame 1 and receive and act upon it in frame 1. But when I fire it in frame 1 and try to handle it in frame 2, it is apparently never received. The event appears to fire fine (I get no errors and see it pass the statement OK in the debugger), but the handler (which also appears to be declared correctly, since I get no compile errors) never seems to receive it. Can someone point me in the proper direction? I really appreciate it! Mike.
Maybe not the problem in your case, but non-static events are tied to the intance, not the class.
DrunkenSailor sailor = new DrunkenSailor(); sailor.HellRaised += new EventHandler(sailor_HellRaised); sailor.RaiseHell(); //event fires sailor = new DrunkenSailor(); sailor.RaiseHell(); //event does not fire. No handler has been assigned to this instance.
This can be missed pretty easliy, especially if the object is reinstantiated elsewhere in your code. In any case, you can check to see if your object's event has any subscribers by looking at the object sending the event in the autos or locals window while debugging. It will read "undefined value" if there are no subscribers. If that's the case, you can begin your hunt to find out why that is. Charlie if(!curlies){ return; } -
I sure could use some help. I have a web app with frames. I want to be able to notify frame2 when something takes place in frame1. Should be simple, but maybe I'm the simple one. I've got the event structure working because I can fire an event in frame 1 and receive and act upon it in frame 1. But when I fire it in frame 1 and try to handle it in frame 2, it is apparently never received. The event appears to fire fine (I get no errors and see it pass the statement OK in the debugger), but the handler (which also appears to be declared correctly, since I get no compile errors) never seems to receive it. Can someone point me in the proper direction? I really appreciate it! Mike.
There's one very important concept you're missing: ASP.NET code that is compiled or that uses server-side scripting (which is compiled at runtime) is SERVER-SIDE ONLY. HTTP - be nature - is non-stateful. Someone clicking a button or link in one frame will not automatically do something in another frame unless 1) you invoke a server-side event that must refresh the whole page, which involves some client-side javascript (or - if you dare - VBScript) to make sure the right frames are updated, or 2) uses client-side script like javascript to perform all actions. This isn't a Windows Forms application where clicking a button could completely rearrange your application UI. Web Applications - built on HTTP - have one fundamental facet: a client requests data, and a server responds with data. So, you have to invoke something that causes the client to request something in frame1 and force a refresh of frame2 all from the client-side! The server cannot push this data to the client (it's impossible when the clients are behind NATs or Web proxies anyway without a persistent connection, in which data can only be appended). This is the nature of HTTP, like it or not.
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
There's one very important concept you're missing: ASP.NET code that is compiled or that uses server-side scripting (which is compiled at runtime) is SERVER-SIDE ONLY. HTTP - be nature - is non-stateful. Someone clicking a button or link in one frame will not automatically do something in another frame unless 1) you invoke a server-side event that must refresh the whole page, which involves some client-side javascript (or - if you dare - VBScript) to make sure the right frames are updated, or 2) uses client-side script like javascript to perform all actions. This isn't a Windows Forms application where clicking a button could completely rearrange your application UI. Web Applications - built on HTTP - have one fundamental facet: a client requests data, and a server responds with data. So, you have to invoke something that causes the client to request something in frame1 and force a refresh of frame2 all from the client-side! The server cannot push this data to the client (it's impossible when the clients are behind NATs or Web proxies anyway without a persistent connection, in which data can only be appended). This is the nature of HTTP, like it or not.
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
I just have to ask. How many hours per day do you put into a workday? It seems like you have a full time job here at CP! How do you keep up? :) -- "We shall crush you down to the point, where there is no coming back, things will happen to you from which you could not recover if you lived a thousand years, a thousand years."
-
I just have to ask. How many hours per day do you put into a workday? It seems like you have a full time job here at CP! How do you keep up? :) -- "We shall crush you down to the point, where there is no coming back, things will happen to you from which you could not recover if you lived a thousand years, a thousand years."
Jörgen, I work with Heath, he is in fact an AI bot that is plugged directly into MSDN and existing Code Project articles. His uptime appears to be running better than most web servers average in a given month. ;) Jörgen Sigvardsson wrote: How do you keep up? He tells M.I.S. jokes. ;P - Nick Parker
My BlogLast time I checked, all programmers have selective ignorance. I know nothing about 3D graphics. I know a lot about COM. VB gets under people's skin because one can be ignorant of computer architecture and ASM and still get a lot done. - Don Box
-
I just have to ask. How many hours per day do you put into a workday? It seems like you have a full time job here at CP! How do you keep up? :) -- "We shall crush you down to the point, where there is no coming back, things will happen to you from which you could not recover if you lived a thousand years, a thousand years."
I work over 60 hours a week typically, but I'm trying to cut back a little because of health problems. I work throughout the day and probably only accumulate an extra 30 minutes to post to CP, sometimes a little more. Being salaried, I decide to spend that time helping other community members. Most of the stuff I know off the top of my head, so I don't have to research anything. The rest is just knowing how to look, which most people it seems don't know how to do - or are to lazy to try.
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----