473,941 Members | 15,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Responding to Command button clicks in Page_Load

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
work because the event isn't raised until after Page_Load has completed and
the HTML output has presumably already been determined.

So if I can't use the Click event, how do I determine during my Page_Load
code which button has been clicked and therefore what output to display?

Thanks

Paul

Nov 18 '05 #1
3 1580
Hi Paul,

In the Form_Load, you can check the string:

Request.Form.To String ()

The last item in the string should be the name of button you click.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Interesting. A very convenient workaround. I tried that and it works for
Button controls but not for LinkButton controls (which is what I would have
preferred to have though I guess it's not essential). If you hit a
LinkButton then the identity of the LinkButton doesn't seem to get added to
the Form data. Which raises two additional questions:
1. Is there any similar workaround for LinkButtons.
2. Is this an 'approved' workaround or is it a hack that happens to work at
the moment but could easily get broken by a future .NET release?

So far the only alternative I've come up with is to manually add some
client-side Javascript to the buttons which sets the value of a hidden
control when each Button (or LinkButton) is clicked. Then back on the server
I can read the value of this hidden control to figure out what button was
clicked. AFAICS that should work, but it looks messy so I don't really want
to do that. (Plus it seems to be exactly the kind of manual boilerplate
coding for managing the controls that I thought ASP.NET was supposed to
release us from).

Paul
"MSFT" <lu******@onlin e.microsoft.com > wrote in message
news:Q8******** ******@cpmsftng xa07.phx.gbl...
Hi Paul,

In the Form_Load, you can check the string:

Request.Form.To String ()

The last item in the string should be the name of button you click.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Hi Paul,

I just found a better solution which also work for a linkbutton:

Page.Request.Fo rm["__EVENTTAR GET"]

Every Form in ASP.NET have a hidden filed "__EVENTTARGET" , we can get the
event sender form this field.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

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

Similar topics

6
2861
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new data from the button is not available at this time as to allow the table to properly update. So basically, I need to call UpdateTable() twice, once from page load and once from button. This causes problems with my application, and I was trying...
4
1293
by: John Smith Jr. | last post by:
I have a very strange problem, I am dynamically creating buttons and events, when page loads the first click works fine, every click there after the event only fires every other click. I made a listbox, and showed when each method fires, and it shows First Click: Page_load, Click Event, Next Click: Page_Load, Next Click: Page_Load, Click Event.
1
1943
by: Milan Todorovic | last post by:
I need some help with my ASP.NET application. The central part of the application is very processing intensive page that can take up to several minutes to process the complex queries and load the aspx page (processing occurs during page load). After it loads the page contains the datagrid (holding a result recordset) and a rather simple web component that contains the several buttons for redirecting. The problem occurs if the page is...
1
2243
by: Klom Dark | last post by:
I've got a weird problem going on - I've got a table of dynamically created buttons. Each button has the X/Y value of the buttons position in the table assigned to it's CommandArgument property and the name of a common command (btn_Command) assigned to it's Command property. The creation of the table is done by a function called drawGeo. drawGeo is called during the initial Page_Load (!IsPostBack), but should be called by btn_Command on...
2
1610
by: McGeeky | last post by:
I use page_load to call a stored procedure and populate the form. When the user clicks the OK button on the form I have implemented an event handler behind it (OKButton_Click()) that calls another stored procedure to insert a record in the database then navigate to a success page. However, when the OKButton_Click() is called the page_load event is also called. This unnescessarilly sets up the page again. How can I stop page_load event...
7
1876
by: Jimmy Jazz | last post by:
Hi, I have created a control with some buttons an alphabet. When one of these buttons are pressed it posts back and in the postback event for the button pressed a list of tems is created with a list of buttons next to them to delete the term. My problem is that the delete button has a delete event attached to it but t does not fire. Is this because the delete butons are created in the postbaclk event and not the CreateChildControls...
2
1827
by: Radu | last post by:
Hi. I have a page with the following html: __________________________________________________________ <h1>Dynamic Controls Test</h1> <hr /> <asp:TextBox ID="txtProduct1" Text="txtProduct 1" runat="server"></ asp:TextBox> <asp:Button ID="cmdAddRow" Text="+" AccessKey="+" runat="server" /> <asp:Button ID="cmdSubtractRow" Text="-" AccessKey="+" runat="server" / <asp:PlaceHolder runat="server" id="placeTextBoxes" />
2
2564
by: CJM | last post by:
I have a page that allows the user to search a DB by querying one of 3 fields. When results are returned, I want the user to be able to click a value in one of three columns (that directly relate to the 3 searchable fields) and have the page postback and requery given the selected criterion. For example, the user searches for retainer #1, which has a Tip Width of 5. So he clicks on the 5 and it searches again for all retainers that have a...
9
3091
by: larryimic | last post by:
I have created a Access production database that records good parts and bad parts to a table thru querys using macros and command buttons on a form. A report (part label) is printed each time a command button is clicked for good or bad parts. When the container is filled with good parts, the operator manualy clicks a command button to print a report (container label). I have been asked to automate the container label report so it prints when...
0
10135
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
11531
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...
1
11297
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10660
tracyyun
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...
0
9862
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
6087
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...
1
4909
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
2
4509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3509
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.