To Find a control that has caused the 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)
        {
            Control c = page.FindControl(ctl);
            if (c is System.Web.UI.WebControls.Button)
            {
                control = c;
                break;
            }
        }
    }
    return control;
}

 

The above code is taken from http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx ... A beautiful example...

 

Cheeers..

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Wednesday, April 04, 2007 10:57 AM

Feedback

# Links (4/4/2007)

left by Member Blogs at 4/25/2007 2:41 PM Gravatar
.NET DataTable vs. BindingList Very Lightweight Data Access Layer in C# and .NET 2.0 WeekNumber A final
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: