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

  • Thread starter Thread starter Jeff User
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
Back
Top