By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

in page_load detect what button was clicked

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.