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

in page_load detect what button was clicked

I am trying to detect what asp.net button was clicked duing the
page_load event. I have two asp.net buttons on my page.

What is the easiest way to detect this?

Nov 19 '05 #1
8 2635
Is there some overarching reason that you picked the Page_Load event? How
about using an Event Handler?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

<th*****************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I am trying to detect what asp.net button was clicked duing the
page_load event. I have two asp.net buttons on my page.

What is the easiest way to detect this?

Nov 19 '05 #2
There is no easy way.

If they are link buttons, you can look at Request.Form["_eventtarget"];

if they are buttons, if the id of the button is in request.form, then that's
the button that was clicked..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<th*****************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I am trying to detect what asp.net button was clicked duing the
page_load event. I have two asp.net buttons on my page.

What is the easiest way to detect this?

Nov 19 '05 #3
I appreciate (sorry ) that I'm not answering your question, but normal
process would be to handle that in the buttons click events. You may be
heading the wrong way if your trying to work around that.

What are you trying to achieve?
Nov 19 '05 #4
I've come across situations where I've cheated on this one also. Typically
it's performance related (not a mindless micro-optimisation either)...

But I agree that it should be called into question and thoroughly examined
:)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Josh" <s@a.com> wrote in message
news:O8**************@TK2MSFTNGP12.phx.gbl...
I appreciate (sorry ) that I'm not answering your question, but normal
process would be to handle that in the buttons click events. You may be
heading the wrong way if your trying to work around that.

What are you trying to achieve?

Nov 19 '05 #5
Yes, of course I would usually handle this in the normal event handler.
But for my case I want to do something like this in my page_load

if(page.ispostback)
{
if (button1 was clicked)
{
//do something
}
else
{
//do some normal postack type stuff
}
}

Nov 19 '05 #6
sam
You can also always render a hidden field in your page and set that
value = to a unique button string identifier in the onlick javascript
for the two buttons. Then on page load you could just check that
hidden field value. Make sure you either declare that hidden field in
the web page or add it in the Init() method, though, otherwise it won't
participant in the load post data phase.

ASP.NET is kindof retarded about this. You would think they would
expose an easy way to let us get this kindof information in the page
load.

-Sam

Nov 19 '05 #7

C#
if(null != Request.Form["buttonName"])
{
// buttonName was clicked
}

VB.NET
If Not Request.Form("buttonName") Is Nothing Then
' buttonName was clicked
End If
<th*****************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I am trying to detect what asp.net button was clicked duing the
page_load event. I have two asp.net buttons on my page.

What is the easiest way to detect this?

Nov 19 '05 #8
Hi,

http://blogs.aspadvice.com/joteke/ar...8/05/1444.aspx

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

<th*****************@yahoo.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Yes, of course I would usually handle this in the normal event handler.
But for my case I want to do something like this in my page_load

if(page.ispostback)
{
if (button1 was clicked)
{
//do something
}
else
{
//do some normal postack type stuff
}
}

Nov 19 '05 #9

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

Similar topics

5
by: Quinn | last post by:
When users clicked a unkown mime type link such as Zip on my website, a "Save/Open/Cancel" dialog box pops up. Is there a way to detect which button users clicked by using ASP? actually I only what...
3
by: Paul Hodgson | last post by:
I have quite a few pages that have multiple command buttons on them - for example one button might be to logout, and others might be to display different segments of the data being shown. The...
1
by: Craig Miles | last post by:
Hi, I have Form1.aspx. Form1 uses client side javascript to launch Form2.aspx when a button is clicked: window.showModalDialog("Form2.aspx?xxxxx=xxxx") etc. The first time the Form1 button is...
2
by: Krista Lemieux | last post by:
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...
2
by: Mark Rae | last post by:
I've inherited an ASP.NET app and have been asked to fix the following problem with a page which is used to display and/or delete records from a database. When the page loads, it displays a list of...
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...
0
by: Alex | last post by:
Hi there! I got some LinkButtons, all declared as "Public Withevents buttonName as LinkButton". I know the button names and IDs. Now I want to check in the Page_Load Method which button was...
17
by: Arpan | last post by:
When a Button is clicked in a Web Form in an ASPX page, the Form will post back to itself. Under such circumstances (i.e. when a Button is clicked), will the Page_Load sub execute first & then will...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...

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.