How to detect which control caused postback
public static Control GetPostBackControl(Page page)
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
if ((ctl.LastIndexOf(".x") > 0) || (ctl.LastIndexOf(".y") > 0))
{
control = page.FindControl(ctl.Substring(0, ctl.Length - 2));
break;
}
control = page.FindControl(ctl);
if ((control is System.Web.UI.WebControls.Button))
{
break;
}
}
}
return control;
}