471,338 Members | 1,196 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

winforms equivalent of asp.net page load event

Hi,

Whats the winforms equivalent of asp.net page load event?

I am trying to clear a status message field every time a user clicks
on any of the buttons..

Jun 27 '08 #1
4 5696
"parez" <ps*****@gmail.comwrote in message
news:4e**********************************@27g2000h sf.googlegroups.com...
Whats the winforms equivalent of asp.net page load event?

I am trying to clear a status message field every time a user clicks
on any of the buttons..
The equivalent would be the Form_Load, but the lifecycle of the winform
is different from the webform. The Class of the webform is created and then
destroyed on every postback, so the Page_Load executes every time you press
a button that submits the form. But the Winform Class is only created once,
and it doesn't recreate every time you press a button (there is no such
thing as a postback in winforms). There is no event that will execute on
every button click except for that button's button_click itself.

If you want a trick to clear your status message on every click on any
button, you can do the following: Write a "button_click" event handler that
clears the message. Then connect that event to every button in the form. You
can do this with a recursive routine that enumerates the Controls
collection. This does not interfere with the existing button_click for each
button, since you can have both event handlers connected to the same event
at the same time.

Jun 27 '08 #2
On May 19, 11:30 am, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.orgwrote:
"parez" <psaw...@gmail.comwrote in message

news:4e**********************************@27g2000h sf.googlegroups.com...
Whats the winforms equivalent of asp.net page load event?
I am trying to clear a status message field every time a user clicks
on any of the buttons..

The equivalent would be the Form_Load, but the lifecycle of the winform
is different from the webform. The Class of the webform is created and then
destroyed on every postback, so the Page_Load executes every time you press
a button that submits the form. But the Winform Class is only created once,
and it doesn't recreate every time you press a button (there is no such
thing as a postback in winforms). There is no event that will execute on
every button click except for that button's button_click itself.

If you want a trick to clear your status message on every click on any
button, you can do the following: Write a "button_click" event handler that
clears the message. Then connect that event to every button in the form. You
can do this with a recursive routine that enumerates the Controls
collection. This does not interfere with the existing button_click for each
button, since you can have both event handlers connected to the same event
at the same time.
Thanks.. I asked the wrong question. but i got the right answer..
Jun 27 '08 #3
On May 19, 11:30 am, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.orgwrote:
"parez" <psaw...@gmail.comwrote in message

news:4e**********************************@27g2000h sf.googlegroups.com...
Whats the winforms equivalent of asp.net page load event?
I am trying to clear a status message field every time a user clicks
on any of the buttons..

The equivalent would be the Form_Load, but the lifecycle of the winform
is different from the webform. The Class of the webform is created and then
destroyed on every postback, so the Page_Load executes every time you press
a button that submits the form. But the Winform Class is only created once,
and it doesn't recreate every time you press a button (there is no such
thing as a postback in winforms). There is no event that will execute on
every button click except for that button's button_click itself.

If you want a trick to clear your status message on every click on any
button, you can do the following: Write a "button_click" event handler that
clears the message. Then connect that event to every button in the form. You
can do this with a recursive routine that enumerates the Controls
collection. This does not interfere with the existing button_click for each
button, since you can have both event handlers connected to the same event
at the same time.
There is a problem. My first event which is wired up by the designer
runs first. The first event handler displays the current message and
the second event handler(button_click) clears it. I wire up the
button_click in my base form Load Event

Is there a way around this problem? or should i look for an
alternative solution for the initial problem?
Jun 27 '08 #4
"parez" <ps*****@gmail.comwrote in message
news:1f**********************************@f63g2000 hsf.googlegroups.com...
There is a problem. My first event which is wired up by the designer
runs first. The first event handler displays the current message and
the second event handler(button_click) clears it. I wire up the
button_click in my base form Load Event

Is there a way around this problem? or should i look for an
alternative solution for the initial problem?
I don't see any elegant and simple workaround.
You could inherit from the Button class, and then in your own button
override the OnClick method. You can then choose wether to call base.OnClick
before or after you execute your own operations such as clearing the
message.
Or you could experiment using a different event for clearing the
message, such as MouseDown, or better still GotFocus, so that it also works
with the keyboard. I think that this fires before the click event, but you
will have to experiment a little bit with the available events to find the
best one.
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Kurt Denhoff | last post: by
reply views Thread by Frank 'Olorin' Rizzi | last post: by
2 posts views Thread by John Alesse | last post: by
2 posts views Thread by John Lau | last post: by
18 posts views Thread by Csaba Gabor | last post: by
2 posts views Thread by ZBINContact | last post: by
23 posts views Thread by raylopez99 | last post: by

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.