473,564 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Pa rams.Get("__EVE NTTARGET"))

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 6673
Request.Form["__EVENTTAR GET"] 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********@mic rosoft.com> wrote in message
news:Pt******** ************@ne ws.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.Pa rams.Get("__EVE NTTARGET"))

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********@mic rosoft.com> wrote in message
news:Pt******** ************@ne ws.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.Pa rams.Get("__EVE NTTARGET"))

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******** ********@TK2MSF TNGP03.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********@mic rosoft.com> wrote in message
news:Pt******** ************@ne ws.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.Pa rams.Get("__EVE NTTARGET"))

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["__EVENTTAR GET"] 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********@mic rosoft.com> wrote in message
news:gf******** ************@ne ws.siol.net...
Request.Form["__EVENTTAR GET"] 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
3150
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 are all set back to their original values. If I do not rebind the datagrid, I don't seem to have access to the dropdownlist at all. Code fragment:
6
1677
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 in the Click_Event in the button control. Unfortunately postback is triggered in the click event before I set the display properties of the control. Is...
7
16010
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 statement like as follows in the PageLoad: private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { //do something...
4
15672
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. When there's a value in the textbox, the (overridden) textchanged event fires and validation is performed. Now I want to turn off autopostback. So I...
3
1602
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 object triggered the postback? -Darrel
7
1618
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 action at that time? 2) How can I prevent any postback from happening on textboxes that I do not want to handle this event on? any info is...
4
9672
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 writing the JavaScript doesn't have to pass the index in the "onChange" event name. I thought that one might be able to use "this.value" or...
3
1045
by: John Smith | last post by:
How can I find out which control performed PostBack?
15
3600
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" and the other listing "Linked Tasks", I have two buttons which in javascript move items from the first list into the second. Then when a user...
0
7665
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...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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. ...
1
7642
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...
0
6255
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...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
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...
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
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...

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.