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 2 2793
Yes, but it isn't pretty...someon e 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["__EVENTTAR GET"] 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
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...someon e 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.IsPostbac k == true and Request.Form
["__EVENTTAR GET"] 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
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 dropdownlist, however
it doesn't work for the button. When the button is clicked, on page load,
Request.Form("__EVENTTARGET") ="". If I call
Page.RegisterHiddenField("__EVENTTARGET", "FakeButton"), then when the
button is clicked,...
|
by: Bob |
last post by:
In the VB.NET Page_Load() function , how can I know which control causes the
page postback?
|
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 button at runtime:
//----- Code snippet
protected System.Web.UI.WebControls.PlaceHolder ImageHolder;
private void Page_Load(object sender, System.EventArgs e)
|
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 initialization routines.
Clicking button 1 causes a postback in which I WANT the initialization
routines to run before the event handler. The net of this is that the same
page redisplays slightly differently.
Clicking button 2 causes a postback in which I...
|
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 site into consideration.
Here is what I want to do:
I have a Button, which starts a new search session. When this session is
started, you have several Usercontrols, which can navigate within the
search session.
| |
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 the usual stuff of
recreating the usercontrol in the Page Init event.
The 'failure' sequence is as follows:
- select web form button to display the user control
- select user control button, event fires
- select web form button to display...
|
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
expected. In the event code for that button, a new LinkButton is added
to the page and is wired up to yet a different event, however when
clicked, the page is posted back but the event is not triggered.
I'm assuming it has something to do with the...
|
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 problem comes in
where I need to raise the event in the second control - the event does
not fire. I have distilled the example below down to it simplest:
on Page_Load one button is created, and a Click event hander is added
to the button. When...
|
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
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |