473,830 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2662
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.goo glegroups.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["_eventtarg et"];

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.goo glegroups.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******** ******@TK2MSFTN GP12.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.ispostb ack)
{
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("b uttonName") Is Nothing Then
' buttonName was clicked
End If
<th************ *****@yahoo.com > wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.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******** *************@g 43g2000cwa.goog legroups.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.ispostb ack)
{
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
8487
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 to record the "valid" click -- when Open/Save was clicked. Thanks ahead. Quinn
3
1571
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 important point is that what gets displayed in the page depends on which command button was clicked in the postback. I'd assumed that I could handle this by sorting out what action to take in the Click event handlers for the buttons, but that doesn't...
1
1267
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 clicked the Form2 Page_Load (server side) is fired. I close Form2 returning to Form1. Click the button again. This time when Form2 loads
2
2799
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 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...
2
2224
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 the 26 letters of the alphabet as hyperlinks which the users then click to return records beginning with that letter, displayed in a DataGrid. The first column of the DataGrid contains a LinkButton which, when clicked, calls the Delete method of...
2
2538
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.
0
1388
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 clicked (depending on which button was clicked I'll fill my datagrid), but I don't know how... I can make "Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, buttonOne.Click" but throught sender...
17
2848
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 the Click event function of the Button execute or will the Click event function of the Button execute first & then will the Page_Load sub execute? Thanks, Arpan
8
2694
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 the button, gets a list of results (each with a LinkButton) and can then press one of the link buttons to get further information. The newly added link buttons appear, but the click event added with AddHandler does not fire. A control added in...
0
9793
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10774
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, 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...
0
10489
jinu1996
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...
0
9314
agi2029
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...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
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...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
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
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.