Getting the control that caused the postback / Das Control ermitteln, welches den Postback ausgelöst hat
protected Control GetPostBackControl()
{
System.Collections.Specialized.NameValueCollection postCollection = System.Web.HttpContext.Current.Request.Form;
string controlID = postCollection.Get("__EVENTTARGET");if (string.IsNullOrEmpty(controlID) == false)
{
return Page.FindControl(controlID);
}foreach (string key in postCollection.Keys)
{
Control control = Page.FindControl(key);if (control is Button)
{
return control;
}
}
return null;
}
Control GetPostBackControl()
{
System.Collections.Specialized.NameValueCollection postCollection = System.Web.HttpContext.Current.Request.Form;
string controlID = postCollection.Get("__EVENTTARGET");if (string.IsNullOrEmpty(controlID) == false)
{
return Page.FindControl(controlID);
}foreach (string key in postCollection.Keys)
{
Control control = Page.FindControl(key);if (control is Button)
{
return control;
}
}
return null;
}
if (string.IsNullOrEmpty(controlID) == false)
{
return Page.FindControl(controlID);
}foreach (string key in postCollection.Keys)
{
Control control = Page.FindControl(key);if (control is Button)
{
return control;
}
}
return null;
}
foreach (string key in postCollection.Keys)
{
Control control = Page.FindControl(key);if (control is Button)
{
return control;
}
}
return null;
}
if (control is Button)
{
return control;
}
}
return null;
}Der untere Teil ist notwendig da Button-Controls nicht die Javascript Funktion "__doPostBack" auslösen, sondern das Form im klassischen ASP(HTML) Stil per Form Submit zurück an den Server schicken. Somit sind Buttons nicht als __EVENTTARGET vermerkt. Etwas schlecht gelöst im ASP.net Framework meiner Meinung nach...