in page_load detect what button was clicked

  • Thread starter Thread starter thomasamillergoogle
  • Start date Start date
T

thomasamillergoogle

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?
 
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.
 
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?
 
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!)
 
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
}
}
 
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
 
C#
if(null != Request.Form["buttonName"])
{
// buttonName was clicked
}

VB.NET
If Not Request.Form("buttonName") Is Nothing Then
' buttonName was clicked
End If
 
Back
Top