欢迎来到.net学习网

欢迎联系站长一起更新本网站!QQ:879621940

您当前所在位置:首页 » ASP.Net » 正文

热门阅读

获取回发服务器控件的ID

创建时间:2011年07月15日 09:07  阅读次数:(6560)
分享到:
许多时候我们需要获取引发回发事件的服务器控件ID,以进行不同的处理.
以下方法或者可以帮到你:
/// <summary >
/// 获取回发的控件ID by wyf
/// </summary >
/// <param name="Page" ></param >
/// <returns ></returns >
protected string getPostBackControlName(Page Page)
{
    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 is System.Web.UI.WebControls.Button ||
                     c is System.Web.UI.WebControls.ImageButton || c is System.Web.UI.WebControls.LinkButton)
            {
                control = c;
                break;
            }
        }
    }
    if (control != null)
        return control.ID;
    else
        return string.Empty;
}
a
来源:.net学习网
说明:所有来源为 .net学习网的文章均为原创,如有转载,请在转载处标注本页地址,谢谢!
【编辑:Wyf

打赏

取消

感谢您的支持,我会做的更好!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

最新评论

共有评论0条
  • 暂无任何评论,请留下您对本文章的看法,共同参入讨论!
发表评论:
留言人:
内  容:
请输入问题 88+18=? 的结果(结果是:106)
结  果: