C#
public Control GetPostBackControl(Page page)Reference: http://www.codeproject.com/Questions/123490/_EVENTTARGET-empty
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control mycontrol = page.FindControl(ctl);
if (mycontrol is System.Web.UI.WebControls.Button)
{
control = mycontrol;
// This gives you ID of which button caused postback
Response.Write(mycontrol.ID);
break;
}
}
}
return control;
}
protected void Page_Load(object sender, EventArgs e)
{
Control a = GetPostBackControl(this.Page);
}
沒有留言:
張貼留言