Welcome to MSDN Blogs Sign in | Join | Help

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

Published Wednesday, November 07, 2007 6:36 AM by Prakash

Comments

# MSDN Blog Postings » How to detect which control caused postback

Anonymous comments are disabled
 
Page view tracker