I am writing some custom logging for our asp.net forms application, and I am able to get the request's url, but on post backs, I would like to get something like __EVENTTARGET to identify what control/button produced said postback.
I thought I could use the Request.Form["__EVENTTARGET"] but within the begin request event, this is set to an empty string on post back.
any idea's of how to get this information on postback? or do I have to wait until the end request to retrieve this information?
Ok, since this doesn't seem to be an interesting question for anyone,
I finally figured out why __EventTarget is not in the Request.Form[] dictionary. asp buttons do not use the _dopostback submittion. Rather, then do a standard form submittion, and send the button's ID in the Request.Form[] dictionary as a field.
lucky for our system, all buttons always start with "btn" so I could identify which button caused the submittion. here is the basic code I came up with:
if (request.HttpMethod == "POST")
{
potentialTarget = request.Form["__EVENTTARGET"];
if (string.IsNullOrWhiteSpace(potentialTarget))
{
foreach (string ctrlName in request.Form)
{
if (!ctrlName.ToLower().Contains("$btn"))
continue;
potentialTarget = ctrlName;
break;
}
}
}