Detect Source of postback

P

Philip Ashworth

Hi,

Does anybody know how to detect the source of a postback. I've debuged the
sender on the page load event and although I see a long list I can't see
what control actually fired the postback.

Regards
Philip Ashworth
 
A

Alvin Bruney [MVP]

I'm not sure what you are asking here, only the page can post to itself in
asp.net. Do you mean you want the control on the page which caused a post?
You wouldn't need that since the control would have fired an event. All
events are hard wired to their respective handlers so if the handler goes
off, the deduction is valid that the control mapped to the event fired it.
Did I miss the boat? Feel free to yell.
 
R

Robert Koritnik

I ran across this question quite some time ago. I got a question from some
developer that wanted to know in the page_load which control is fiiring the
event, because events are processed later... But. In normal situations if
you have to do something like this, your design approach is wrong. Every
page Get/Post execution can and MUST if possible be written the "normal" way
that means fiiring control related events and without any processing in the
Initialize phase.

Probably you're making a problem with it.

But beside that if you really want to get your hands dirty with this, get
the controls name in:
Request["__EVENTTARGET"];

but you'll have to change ":" into "_". But that still wouldn't get you
right in because this way, you'll get ClientID, not the actual ID, but
you'll be nearer to your goal. Actually you'd be doing your own
ProcessPostBackData() which normally gets called and parses the originator
of the postback and preparing the data for fiiring control events at every
single postback.
 
P

Philip Ashworth

Thanks for the reply guys,

In the end I modified the control to raise an event. (I looked at the
Request["__EVENTTARGET"] Robert but it had nothing in it.

Cheers Phil


Robert Koritnik said:
I ran across this question quite some time ago. I got a question from some
developer that wanted to know in the page_load which control is fiiring the
event, because events are processed later... But. In normal situations if
you have to do something like this, your design approach is wrong. Every
page Get/Post execution can and MUST if possible be written the "normal" way
that means fiiring control related events and without any processing in the
Initialize phase.

Probably you're making a problem with it.

But beside that if you really want to get your hands dirty with this, get
the controls name in:
Request["__EVENTTARGET"];

but you'll have to change ":" into "_". But that still wouldn't get you
right in because this way, you'll get ClientID, not the actual ID, but
you'll be nearer to your goal. Actually you'd be doing your own
ProcessPostBackData() which normally gets called and parses the originator
of the postback and preparing the data for fiiring control events at every
single postback.

--
RobertK
{ Clever? No just smart. }


Philip Ashworth said:
Hi,

Does anybody know how to detect the source of a postback. I've debuged the
sender on the page load event and although I see a long list I can't see
what control actually fired the postback.

Regards
Philip Ashworth
 
R

Robert Koritnik

It depends on the type of submit to have _EVENTTARGET filled. Normally all
controls that start a postback with javascript DO FILL this hidden field.
You should probably send some code to help you more thoroughly.
But if you changed your control so it works fine now without knowing this
info, you've been looking for, it's probably the best thing to do.

--
RobertK
{ Clever? No just smart. }


Philip Ashworth said:
Thanks for the reply guys,

In the end I modified the control to raise an event. (I looked at the
Request["__EVENTTARGET"] Robert but it had nothing in it.

Cheers Phil


Robert Koritnik said:
I ran across this question quite some time ago. I got a question from some
developer that wanted to know in the page_load which control is fiiring the
event, because events are processed later... But. In normal situations if
you have to do something like this, your design approach is wrong. Every
page Get/Post execution can and MUST if possible be written the "normal" way
that means fiiring control related events and without any processing in the
Initialize phase.

Probably you're making a problem with it.

But beside that if you really want to get your hands dirty with this, get
the controls name in:
Request["__EVENTTARGET"];

but you'll have to change ":" into "_". But that still wouldn't get you
right in because this way, you'll get ClientID, not the actual ID, but
you'll be nearer to your goal. Actually you'd be doing your own
ProcessPostBackData() which normally gets called and parses the originator
of the postback and preparing the data for fiiring control events at every
single postback.

--
RobertK
{ Clever? No just smart. }


Philip Ashworth said:
Hi,

Does anybody know how to detect the source of a postback. I've debuged the
sender on the page load event and although I see a long list I can't see
what control actually fired the postback.

Regards
Philip Ashworth
 

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
474,125
Messages
2,570,748
Members
47,302
Latest member
MitziWragg

Latest Threads

Top