Profile image for Jonathan Orroi jonathanorroi
found at: http://ryanfarley.com/blog/archi...

If there are more buttons you need to change the code.

If you want to include buttons to "page.Request.Params.Get("__EVENTTARGET");" --> add parameter to button: UseSubmitBehavior="False"
Language
C#
Tags
button control postback

Determing the control that caused a PostBack

1 public static Control GetPostBackControl(Page page) 2 { 3 Control control = null; 4 5 string ctrlname = page.Request.Params.Get("__EVENTTARGET"); 6 if (ctrlname != null && ctrlname != string.Empty) 7 { 8 control = page.FindControl(ctrlname); 9 } 10 else 11 { 12 foreach (string ctl in page.Request.Form) 13 { 14 Control c = page.FindControl(ctl); 15 if (c is System.Web.UI.WebControls.Button) 16 { 17 control = c; 18 break; 19 } 20 } 21 } 22 return control; 23 }

Comments