how to determine (on server) which (client) event fired

J

Jeff User

Hi
I have a WebControls.DropDownList.
autoPostBack is set to true.
I have code (C#) in the event procedure in the code behind and it
works fine. OK, now my problem is this:
While in the Page_Load event, I want to be able to determine, what
event, if any, caused the page to be loading.
ie. maybe there are several possible user control events that could
have occured. Which one brought me here?
So
If the DropDown (index changed, or whatever event) ran before the
Page_Load, I would know that this event fired (because I would be in
the DropDown event procedure) and I could set a flag or whatever but,
when this event fires and posts back, the Page_Load event runs before
the DropDown event.

So how, can I determine what event just fired, before I get to its
specific event procedure?

Thanks
Jeff
 
P

Peter Rilling

All the information you need should be in the posted form data. Take a look
at the form fields passed to your code and see if you can parse that
information.
 
W

Wouter van Vugt

Hi Jeff,

take a look at the __EVENTTARGET posted value. It contains the ID of
control which is being posted to.

Grtz, Wouter van Vugt
Info Support
www.dive-in-it.nl
 
J

Jeff User

Thanks guys

How do I get to the _EVENTTARGET value?

I was trying to use Context.Request.Params
but couldnt figure out what to do after Params.
Context.Request.Params.Keys? but not sure what to do with/after Keys?

Can anyone help me structure this statement? I did not find any
examples at all.

Thanks again
Jeff
 
J

Jeff User

I try this:
string eventVal = "";
eventVal = Request.Form.GetValues("_EVENTTARGET").ToString();

Yields error at run time:
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Doesn't matter if this executed during postback or not.

Any details that anyone could provide is much appreciated.

Thanks again
 
J

Jeff User

Fixed it!

sEventTarget = Request.Form.GetValues("__EVENTTARGET");
now works. Although .ToString() on the end was not correct,it was
not the problem. The problem was that the name of the value that I
wanted contains 2 underscores "__", and I was only using 1 "_".

Thanks for the guidance
Jeff
 

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,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top