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

Which control has performed (triggered) PostBack event?


How can I find out which control performed PostBack?

I have put this code inside my Page_Load event:

Response.Write(Page.Request.Params.Get("__EVENTTAR GET"))

but it doesn't write to response anything when I click on the button inside
DataGrid (my asp:Button is located inside my template column togrther with
my asp:TextBox). It works fine for DropDownList, which is also inside
template column inside DataGrid.
Jun 15 '06 #1
6 6664
Request.Form["__EVENTTARGET"] will only be available when a control other
than a button caused postback. That's because <asp:button's> generate a
postback naturally in HTML without the help of javascript. LinkButton's and
DropDownList's for example require JavaScript to do a postback, and thus
write into __EVENTARG.

Unfortunetly, the only way to determine which button causes a postback
(without waiting for the event handler to fire), is to loop through
Request.Form and look for the button's UniqueID. Which ever button causes
the postback will be in the Request.Form collection - all other button's
won't be.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"John Smith" <jo********@microsoft.com> wrote in message
news:Pt********************@news.siol.net...

How can I find out which control performed PostBack?

I have put this code inside my Page_Load event:

Response.Write(Page.Request.Params.Get("__EVENTTAR GET"))

but it doesn't write to response anything when I click on the button
inside
DataGrid (my asp:Button is located inside my template column togrther with
my asp:TextBox). It works fine for DropDownList, which is also inside
template column inside DataGrid.

Jun 15 '06 #2
In addition to what Karl said, typically, you shouldn't need to do this. You
handle the appropriate event for each control, and it will get called if
necessary. So if you clicked button A, button A's click handler will be
called without you having to do anything. If it was button B, then button
B's click handler will get called. You shouldn't need to manually figure
this out unless you are doing something unusual.

"John Smith" <jo********@microsoft.com> wrote in message
news:Pt********************@news.siol.net...

How can I find out which control performed PostBack?

I have put this code inside my Page_Load event:

Response.Write(Page.Request.Params.Get("__EVENTTAR GET"))

but it doesn't write to response anything when I click on the button
inside
DataGrid (my asp:Button is located inside my template column togrther with
my asp:TextBox). It works fine for DropDownList, which is also inside
template column inside DataGrid.

Jun 15 '06 #3
I agree, though I've had some cases where I've had to look right into
Request.Form. It always feels uncomfortable, but it might be necessary to
shortcircuit heavy processing in some cases. If at all possible, such code
should be pushed to the PreRender event, which will happen after the
eventHandler fires, but that's also not always possible.

I think to recap...make sure you actually have to do this before doing it :)

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
In addition to what Karl said, typically, you shouldn't need to do this.
You handle the appropriate event for each control, and it will get called
if necessary. So if you clicked button A, button A's click handler will
be called without you having to do anything. If it was button B, then
button B's click handler will get called. You shouldn't need to manually
figure this out unless you are doing something unusual.

"John Smith" <jo********@microsoft.com> wrote in message
news:Pt********************@news.siol.net...

How can I find out which control performed PostBack?

I have put this code inside my Page_Load event:

Response.Write(Page.Request.Params.Get("__EVENTTAR GET"))

but it doesn't write to response anything when I click on the button
inside
DataGrid (my asp:Button is located inside my template column togrther
with
my asp:TextBox). It works fine for DropDownList, which is also inside
template column inside DataGrid.


Jun 15 '06 #4
Request.Form["__EVENTTARGET"] will only be available when a control other
than a button caused postback. That's because <asp:button's> generate a
postback naturally in HTML without the help of javascript. LinkButton's
and DropDownList's for example require JavaScript to do a postback, and
thus write into __EVENTARG.


Your explanation helped me, but I still haven't solved my problem entirely.
When my asp:TextBox have focus then my asp:Button changed its color,
indicating that it will submit form on ENTER keyboard button pressed. I do
have the OnClick event associated with this button, but it doesn't execute
when I press ENTER inside my asp:TextBox, because this button is not inside
Request.Form array. The button is not inside Request.Form array of
components because (I think) ASP.Net event was not fired, but natural HTML
event was fired. When I click my asp:Button with mouse pointer, the OnClick
event fire.

What should I do? :(
Jun 16 '06 #5
Well, in ASP.NET 1.1, hitting "enter" in a textbox will cause the first
button in the form to submit. This is an HTML behaviour. It should be
causing the event handler to fire though - that's strange. In asp.net 2.0,
you can control which button is fired when enter is clicked in each textbox.
My guess is that this is done via javascript and __EVENTTARGET would be
used.

If you want finer control over enter in textboxes in 1.x, check out:
http://www.allasp.net/enterkey.aspx

it might solve ur problem too..

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"John Smith" <jo********@microsoft.com> wrote in message
news:gf********************@news.siol.net...
Request.Form["__EVENTTARGET"] will only be available when a control
other
than a button caused postback. That's because <asp:button's> generate a
postback naturally in HTML without the help of javascript. LinkButton's
and DropDownList's for example require JavaScript to do a postback, and
thus write into __EVENTARG.


Your explanation helped me, but I still haven't solved my problem
entirely. When my asp:TextBox have focus then my asp:Button changed its
color, indicating that it will submit form on ENTER keyboard button
pressed. I do have the OnClick event associated with this button, but it
doesn't execute when I press ENTER inside my asp:TextBox, because this
button is not inside Request.Form array. The button is not inside
Request.Form array of components because (I think) ASP.Net event was not
fired, but natural HTML event was fired. When I click my asp:Button with
mouse pointer, the OnClick event fire.

What should I do? :(

Jun 16 '06 #6
If you want finer control over enter in textboxes in 1.x, check out:
http://www.allasp.net/enterkey.aspx

it might solve ur problem too..


Yes, it helped me. :> Thank you.
Jun 20 '06 #7

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

Similar topics

1
by: pete | last post by:
Hello all, I'l displaying a dropdownlist inside a datagrid. The problem comes when I try to get the values the user chose on postback. If I rebind the datagrid, the values of the dropdownlist...
6
by: Angel | last post by:
I have a button, combo, and custom control that i created. When I click the button i want to set certain display properties of my custom control depending whats in the combo. I set those properties...
7
by: Amadelle | last post by:
Hi all and thanks in advance, I am stuck! I can't figure out how to identify which button was clicked on my ASP.NET page in the PostBack event? So what I am trying to do is to is to have an if...
4
by: owingruters | last post by:
Hi all, I've created an User control. It's an extension of a textbox wich has some extra properties so that validation becomes a lot faster. The control wordks great if autopostback is on....
3
by: darrel | last post by:
I have a page that checks to see if it's a postback on page_load. I want it to do one of two different things depending on which object triggered the postback. Is there a way to check to see which...
7
by: djc | last post by:
I noticed that after entering text into a textbox on an asp.net webform and then hitting the enter key that a postback appears to be performed. 1) what event can I write to in order to perform an...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
3
by: John Smith | last post by:
How can I find out which control performed PostBack?
15
by: mc | last post by:
I'm writing an app for managing Task Lists, I'm trying to add some controls to a form that I can use to link tasks, my original intention was to: - Add two list boxes, one listing "all Tasks"...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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,...

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.