private string getPostBackControlName()
{
Control control = null;
string ctrlname = Page.Request.Params["__EVENTTARGET"];
if (ctrlname != null && ctrlname != String.Empty)
{
control = Page.FindControl(ctrlname);
}
else
{
Control c;
foreach (string ctl in Page.Request.Form)
{
if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
{
c = Page.FindControl(ctl.Substring(0, ctl.Length - 2));
}
else
{
c = Page.FindControl(ctl);
}
if (c!=null)
{
control = c;
break;
}
}
}
if (control != null)
return control.ID;
else
return string.Empty;
}
获取引发页面回传事件的控件
本文介绍了一个用于ASP.NET的实用方法,该方法能够帮助开发者通过PostBack事件找到触发此事件的控件名称。这对于处理复杂的页面事件非常有用,尤其是在需要确定哪个控件触发了特定PostBack操作时。

被折叠的 条评论
为什么被折叠?



