어떤 버튼을 클릭했는지 파악하려고하는데이 코드는 IE에서 제대로 작동하지만 Chrome, Firefox 또는 Safari라면 아무 것도하지 않습니다. 파이어 폭스에서 파이어 버그를 사용할 때 폼 세부 정보를 살펴본 결과, EVENTTARGET에는 값이 없음을 알 수 있습니다. FF, Chrome 및 Safari에서 어떻게 작동합니까?EVENTTARGET 보낸 사람을 확인하는 중 문제가 발생했습니다.
방법 : 메서드를 호출
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;
코드 :
if (Page.IsPostBack)
{
try
{
Control cause = GetPostBackControl(Page);
string statecause = cause.ID;
if (statecause == "buttonName1")
{
search(statecause);
}
else if (statecause == "buttonNAME2")
{
resetfields();
}
}
catch { }
}