Postback Question

  • Thread starter Thread starter Robert Galvin
  • Start date Start date
Yes. There are actually two:

1. If you create a postback event for the control, you can simply handle
through that event. Double-clicking a control handles this.

2. If not, you can use the sender to determine which control. First, GetType
off sender, then cast as that type to get name, etc.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
Hallo Robert
Robert Galvin said:
Is it possible to tell which control caused a postback?
I dont think so, but i might be wrong. But what you can do, is to use
functions on your controls to determine that. for example you have 2
buttons:
<asp:Button ID="btn1" Text="send1" Runat="server" OnClick="function1" />
<asp:Button ID="btn2" Text="send2" Runat="server" OnClick="function2" />

function1 will be executed when btn1 is clicked, and function2 when btn2 is
clicked.

regards benni
 
Benni,

Thank you for the reply.
I am doing all my code in code behind. I have a need to know which control
caused the postback before any events are triggered. I would like to know
this in the page init or the page load.

Thank You.

Robert
 
Thanks Gregory.

When I check the sender in my page load event it always returns the name of
my .aspx

Robert
 
Gregory,

I really appreciate all your help on this. I'm going to review what I am
doing and will reply later if needed.

Thank you very much.

Robert
 
Robert,

If you insist on not using server-side events, you will probably have to get
the client side to supply the control id in a hidden html <input>. For this
you can use form's onsubmit event. You can get control id as
event.srcElement.id. Just note, that if the form calls submit() method,
onsubmit event won't fire and you will have to set the hidden input value
every time before calling submit().

Eliyahu
 
Back
Top