I am trying to figure out what button was clicked, this code works just fine in IE, but if I Chrome, Firefox, or Safari it doesnt do anything. When using firebug in firefox, I looked at the Form Details, and it shows that EVENTTARGET has no value its just blank. How can I get this to work on FF, Chrome, and Safari?
Method:
Control postbackControlInstance = null;
string postbackControlName = page.Request.Params.Get("__EVENTTARGET");
if (postbackControlName != null && postbackControlName != string.Empty)
{
postbackControlInstance = page.FindControl(postbackControlName);
}
else
{
for (int i = 0; i < page.Request.Form.Keys.Count; i++)
{
postbackControlInstance = page.FindControl(page.Request.Form.Keys[i]);
if (postbackControlInstance is System.Web.UI.WebControls.Button)
{
return postbackControlInstance;
}
}
}
if (postbackControlInstance == null)
{
for (int i = 0; i < page.Request.Form.Count; i++)
{
if ((page.Request.Form.Keys[i].EndsWith(".x")) || (page.Request.Form.Keys[i].EndsWith(".y")))
{
postbackControlInstance = page.FindControl(page.Request.Form.Keys[i].Substring(0, page.Request.Form.Keys[i].Length - 2));
return postbackControlInstance;
}
}
}
return postbackControlInstance;
Code Calling Method:
if (Page.IsPostBack)
{
try
{
Control cause = GetPostBackControl(Page);
string statecause = cause.ID;
if (statecause == "buttonName1")
{
search(statecause);
}
else if (statecause == "buttonNAME2")
{
resetfields();
}
}
catch { }
}