使用 JavaScript 单击 RadGrid 中的链接

Clicking a link in RadGrid using JavaScript

本文关键字:链接 RadGrid JavaScript 单击 使用      更新时间:2023-09-26

我使用RadGrid绑定记录,每一行都有一个链接按钮。如果我单击该链接,它将打开moalpopup(根据某些条件它是动态的)。当我使用关闭按钮关闭弹出窗口时,它应该继续链接按钮事件。

代码隐藏:

protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
    {
        LinkButton link = ((LinkButton)gridDataItem.FindControl("link"));
        ModalPopupExtender popup = (ModalPopupExtender)e.Item.FindControl("popup");
        Image imageClose = (Image)e.Item.FindControl("imageClose");
        popup.TargetControlID = link.ID;
        link.Attributes.Add("onclick", "return false;"); // to avoid postback and stay in page and show popup
        imageClose.Attributes.Add("onclick", "proceed('" + link.ClientID + "')");
    }
}

Javascript:

function proceed(id)
{
    window.document.getElementById(id).removeAttribute("onclick"); // Link button - to remove "onclick" attribute
    window.document.getElementById(id).click(); //  trigger click event
}

我尝试使用上面的代码,该属性未删除,并且不继续链接按钮事件。

我终于做到了。这个正如我预期的那样完美地工作。

function proceed(id)
{
    document.location.href = $('#' + id).attr("href");
}