Home
Manage Your Code
Snippet: Gets the Control that posted back (ASP.NET)
Title: Gets the Control that posted back Language: ASP.NET
Description: Gets Views: 1276
Author: David Carter Date Added: 8/17/2007
Copy Code  
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)
			{
				Control c = page.FindControl(ctl);
				if (c is Button)
				{
					control = c;
					break;
				}
			}
		}
		return control;
	}