473,396 Members | 2,033 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.

Detecting control that causes postback in asp.net 2003

I have a page with two textboxes and two buttons which post back to
the server. I want to detect which button has been clicked for
testing purposes preferably clientside, but otherwise serverside.
However, when I examine Page.Request.Form("__EventTarget") in my
aspx.vb Page Load sub , Page.Request.Form("__EventTarget") is nothing.
If I view source, the DoPostback function is not visible, nor are the
hidden EventTarget and EventArgument fields. However, if I add a
dropdown list to the page, these script blocks are inserted. On this
occasion, I find that Page.Request.Form("__EventTarget") is an empty
string.
When I add an editable datagrid control to the page and go into edit
mode by clicking a link button, when I click the update or cancel link
buttons Page.Request.Form("__EventTarget") is populated with the id of
the control I have clicked. Can anyone please tell me
1. why a button does not use the DoPostback function
2. in that case what I can use serverside to determine which button
caused the postback as Page.Request.Form("__EventTarget") is empty
3. how I detect which control caused the postback using clientside
Javascript
Thanks
Roz Lee
Nov 18 '05 #1
1 5746
Hi Roz,
as far as I know..
1. why a button does not use the DoPostback function
asp.net buttons are rendered as <INPUT type='submit'> in
html, so when they are clicked the form is submitted - as
in standard asp. As far as I can determine, the
__doPostBack function is rendered to the client if there
exists a server-side control that posts-back to the
server that IS NOT A BUTTON.
2. what I can use serverside to determine which button
caused the postback as Page.Request.Form ("__EventTarget") is empty

Assuming you've clicked an asp.net button control, I
don't think you can get the id of the button out of the
Page_Load event. You'll have to wire up a server-side
event handler for the button, and use that to 'determine'
that the button has been clicked. This seems to be
shortcoming of the button control in asp.net.
3. how I detect which control caused the postback using clientside

There may be a better shortcut, but you could easily
write a function that is called on the client onclick
event of each button/similar-control on your form that
passes the id of the control into the function.

hope this is of use.

alex
-----Original Message-----
I have a page with two textboxes and two buttons which post back tothe server. I want to detect which button has been clicked fortesting purposes preferably clientside, but otherwise serverside.However, when I examine Page.Request.Form ("__EventTarget") in myaspx.vb Page Load sub , Page.Request.Form ("__EventTarget") is nothing. If I view source, the DoPostback function is not visible, nor are thehidden EventTarget and EventArgument fields. However, if I add adropdown list to the page, these script blocks are inserted. On thisoccasion, I find that Page.Request.Form("__EventTarget") is an emptystring.
When I add an editable datagrid control to the page and go into editmode by clicking a link button, when I click the update or cancel linkbuttons Page.Request.Form("__EventTarget") is populated with the id ofthe control I have clicked. Can anyone please tell me
1. why a button does not use the DoPostback function
2. in that case what I can use serverside to determine which buttoncaused the postback as Page.Request.Form ("__EventTarget") is empty3. how I detect which control caused the postback using clientsideJavascript
Thanks
Roz Lee
.

Nov 18 '05 #2

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

Similar topics

3
by: Joe Loyd | last post by:
I have a Web form made up of several panels of controls. On postback, I need to detect if any of the controls were updated. Is there something like a "Panel.Changed" event or am I stuck iterating...
2
by: Jeff Voigt | last post by:
Is there any way to dynamically get the name of the control that caused the postback? Since SmartNav is not working for me I'm trying to implement a way to scroll to the control that caused the...
0
by: Xavier Osa | last post by:
Hi, I have an ASP.Net web page that you can download a file. As Fergunson's problem, it prompts twice dialog boxes only if I select Open button. If I select Save button, it prompts once. I'm...
1
by: Mad Scientist Jr | last post by:
I don't know how this is happening, but a dropdown control I have is resetting to the 2nd value on the list anytime a postback occurs. I have no initiation code outside of If Not (IsPostBack) ...
4
by: peshrad | last post by:
Hi ! I'm working with Win 2K and Visual Studio 2003. I have a problem because pressing <ENTER> in a text input control causes a postback of my web form. Here comes some example code (already...
1
by: Dood | last post by:
I have a page that has a tab control which toggles which user control is loaded into a placeholder. The user controls that are loaded into this place holder have other user controls in them, making...
6
by: John Smith | last post by:
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("__EVENTTARGET")) but it doesn't write to response...
4
by: wardy | last post by:
Hi all, Looking for a bit of help with this one...I have a situation where I need to be able to determine the control that initiated a form's submit action in client-side Javascript. I am...
2
by: HammRadio | last post by:
I am exploring converting my web app (current Framework 1.1) to Framework 2.0. Everything went smoothly save for one item. To reduce the trips to the database, when loading user controls (like a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...

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.