473,322 Members | 1,562 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,322 software developers and data experts.

Reading Event Objects (like a clicked button) at Page_Load

Hello,

In my form I have a button, and the button_Click function
(which gets called when the button is clicked). However
the functionality that I have in the button_Click
function, needs to be in the Page_Load, since I need to
change a value based on the button click to render the
page. So my question is, can I access the button object
(the sender of the event) in the Page_Load. So that in
the Page_Load I can have the following functionality:
If Button1 is pressed then Do this
If Button2 is pressed then do that
If Button3 is pressed then do ... and so on...

Is this possible?

Thank you very much for your help.

Merci,
Krista Lemieux
Nov 18 '05 #1
2 2778
Yes, but it isn't pretty...someone might already have written a control out
there to do this, but basically:

If you only have 1 button, you can assess that the button has been pressed
by the following rule:
Page.IsPostback == true and Request.Form["__EVENTTARGET"] is null

Now, this isn't your case (unfortunetly), so you have two options:

(I just thought of this one, but I likes it!)
1 - Add a javascript onClick that'll store the Id of the button being
clicked in a hidden form field, retrieve the id in Page_Load which'll let
you do a FindControl() for the button. This could be nicely wrapped in a
server control which extends the existing Button functionality.

2 - Your Restquest.Form collection will only have the value of the button
that was clicked. You can loop through it until you find the id/name of a
button, an dyou'll know that was the clicked one.

Karl

"Krista Lemieux" <ki***********@hotmail.com> wrote in message
news:b4****************************@phx.gbl...
Hello,

In my form I have a button, and the button_Click function
(which gets called when the button is clicked). However
the functionality that I have in the button_Click
function, needs to be in the Page_Load, since I need to
change a value based on the button click to render the
page. So my question is, can I access the button object
(the sender of the event) in the Page_Load. So that in
the Page_Load I can have the following functionality:
If Button1 is pressed then Do this
If Button2 is pressed then do that
If Button3 is pressed then do ... and so on...

Is this possible?

Thank you very much for your help.

Merci,
Krista Lemieux

Nov 18 '05 #2
Hi Karl,

Ohh my, I though that there would be some direct way to
do this, but from what you're telling me, there isn't...
However I do think your idea is really good, and I'll
definatelly use, since there is no direct way through
the .NET freamwork.

Thank you for your help.

Merci,
Krista Lemieux
-----Original Message-----
Yes, but it isn't pretty...someone might already have written a control outthere to do this, but basically:

If you only have 1 button, you can assess that the button has been pressedby the following rule:
Page.IsPostback == true and Request.Form ["__EVENTTARGET"] is null
Now, this isn't your case (unfortunetly), so you have two options:
(I just thought of this one, but I likes it!)
1 - Add a javascript onClick that'll store the Id of the button beingclicked in a hidden form field, retrieve the id in Page_Load which'll letyou do a FindControl() for the button. This could be nicely wrapped in aserver control which extends the existing Button functionality.
2 - Your Restquest.Form collection will only have the value of the buttonthat was clicked. You can loop through it until you find the id/name of abutton, an dyou'll know that was the clicked one.

Karl

"Krista Lemieux" <ki***********@hotmail.com> wrote in messagenews:b4****************************@phx.gbl...
Hello,

In my form I have a button, and the button_Click function (which gets called when the button is clicked). However
the functionality that I have in the button_Click
function, needs to be in the Page_Load, since I need to
change a value based on the button click to render the
page. So my question is, can I access the button object
(the sender of the event) in the Page_Load. So that in
the Page_Load I can have the following functionality:
If Button1 is pressed then Do this
If Button2 is pressed then do that
If Button3 is pressed then do ... and so on...

Is this possible?

Thank you very much for your help.

Merci,
Krista Lemieux

.

Nov 18 '05 #3

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

Similar topics

6
by: Bob | last post by:
Hello, For web controls which can invoke __doPostBack. At the page load, I supposedly can know who caused the PostBack by checking Request.Form("__EVENTTARGET"). It does work for the...
12
by: Bob | last post by:
In the VB.NET Page_Load() function , how can I know which control causes the page postback?
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
3
by: Rich | last post by:
Hi everyone, I have run into a quandry here. Here is a simplified scenario that mirrors my real problem. I have a page that has 2 buttons: On page load, the page runs some complex...
2
by: Frank Schumacher | last post by:
Hi Folks, I have a problem with the order of events fired by ASP.NET. I found many articles which explaining the lifecycle of a site, but I found none which took the event from a Control on the...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
2
by: Chu | last post by:
Thanks everyone for taking a moment to read this. I've got a page where I use a LinkButton and I wire up a dynamic event to the button. When the user clicks the button, the event is fired as...
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...
4
by: bbawa1 | last post by:
I have a button( btnLogOut)in my master page. In page_load event of this master page I want to verify if the button is clicked or not. How can I do that. Thanks in advance. seema
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...
1
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: 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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.