Detecting control that causes postback in asp.net 2003

R

Roz Lee

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
 
A

alex bowers

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top