尝试这个:
Control ctrl = null;
string target = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(target))
ctrl = page.FindControl(target);
if(ctrl == check){
//check is the control that caused postback
}
** 更新 **
好的,结果 ImageButtons 的功能有点不同。将此用于您的标记:
<asp:ImageButton onClientClick="setTarget(this.id)" ID="check" runat="server" ImageUrl="../img/process.png" OnClick="check_Click" CausesValidation="false" UseSubmitBehavior="false"/>
<asp:HiddenField ID="targetId" runat="server" />
现在创建一个 javascript 函数,它将使用启动 PostBack 的字段的 ID 填充我们的隐藏字段:
function SetSource(id)
{
var targetId=
document.getElementById("<%=targetId.ClientID%>");
targetId.value = id;
}
最后我们在 PostBack 中检查它:
Control ctrl = null;
if (Request.Form[targetId.UniqueID] != null &&
Request.Form[targetId.UniqueID] != string.Empty)
{
ctrl = Page.FindControl(Request.Form[targetId.UniqueID]);
}
if(ctrl == check){
//check is the control that caused postback
}
参考:http ://www.aspsnippets.com/Articles/How-to-find-the-control-that-caused-PostBack-in-ASP.Net.aspx