Thursday, September 24, 2009

Find the control that raised postback event on a page in c#

Using this method you may find the control that raised the PostBack event on a page.

Code in C#:

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;
}

1 comment:

கொங்கு நா.அருண் said...

but how can i get People Editor auto post back event using this code...
please suggest me to find a solution...