How to see what caused PostBack

B

Bisser Milanov

I have few buttons on a page. In Page_Load I would like to determine which
one caused post back. How to do?
 
N

Natty Gur

Hi,

You can check the value in the Form __EVENTTARGET field.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
N

Natty Gur

I forgot, one more way is to overload the RaisePostBackEvent. the
IPostBackEventHandler got the Control ID.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
B

Bisser Milanov

__EVENTTARGET is always empty and I couldn't find such event as RaisePostBackEvent.
I forgot, one more way is to overload the RaisePostBackEvent. the
IPostBackEventHandler got the Control ID.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
N

Natty Gur

OK right buttons dont use the __Dopostback so the EVENTTARGET field is
empty,

1) If you look at the Form.Keys collection you will found the Button ID
that cause the postback.

2) RaisePostBackEvent is a method that you need to overload it :
override protected void RaisePostBackEvent ( IPostBackEventHandler
sourceControl,
string eventArgument)
{
string s = ((WebControl)sourceControl).ID ;
}

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top