在从后端C#代码单击的hfref上打开一个弹出窗口

时间:2018-08-13 23:08:24

标签: c# radgrid

我正在尝试从ahref上的后端c#代码打开一个弹出窗口。 Open the Popup

如您所见,这是在数据表行上完成的

    foreach(LinkCustomerFile lcf in linkedCustomerFiles)
    {
     var readLinkType = ecfsc.GetLinkType(lcf.LinkType.LinkTypeId,DateTime.Now,Page.User.Identity.Name);
           dt.Rows.Add("7","45",readLinkType,string.Format("<a href='../LinkCustomerFiles.aspx?action={0}&customerFileId={1}&referenceNumber={2}&linkcustId={3}' target='popup'>{0} </a>  ","Remove",lcf.CustomerFile.CustomerFileId,lcf.RefCustomerFile.CustomerFileId,lcf.LinkCustomerFileId));
   }
    RadGridLink.DataSource=dt;
    RadGridLink.DataBind();

当用户单击删除

时,是否可以通过此代码来实现弹出窗口?

1 个答案:

答案 0 :(得分:0)

只需少量添加代码即可。

第一个)。只需直接在代码的OnClick属性上添加JavaScript代码即可。

@foreach(LinkCustomerFile lcf in linkedCustomerFiles)
            {
            var readLinkType = ecfsc.GetLinkType(lcf.LinkType.LinkTypeId,DateTime.Now,Page.User.Identity.Name);
            dt.Rows.Add("7","45",readLinkType,string.Format("<a href='../LinkCustomerFiles.aspx?action={0}&customerFileId={1}&referenceNumber={2}&linkcustId={3}' target='popup' onclick='return confirm('Are you sure you want to Logout?')'>{0} </a>  ","Remove",lcf.CustomerFile.CustomerFileId,lcf.RefCustomerFile.CustomerFileId,lcf.LinkCustomerFileId));
            }
            RadGridLink.DataSource=dt;
            RadGridLink.DataBind();

2nd)另一种方法是添加Javascript代码:

<script>
function myFunction() {
   return confirm('Are you sure you want to Logout?')
}
</script>

然后直接在代码中调用该函数:

@foreach(LinkCustomerFile lcf in linkedCustomerFiles)
            {
            var readLinkType = ecfsc.GetLinkType(lcf.LinkType.LinkTypeId,DateTime.Now,Page.User.Identity.Name);
            dt.Rows.Add("7","45",readLinkType,string.Format("<a href='../LinkCustomerFiles.aspx?action={0}&customerFileId={1}&referenceNumber={2}&linkcustId={3}' target='popup' onclick='myFunction()'>{0} </a>  ","Remove",lcf.CustomerFile.CustomerFileId,lcf.RefCustomerFile.CustomerFileId,lcf.LinkCustomerFileId));
            }
            RadGridLink.DataSource=dt;
            RadGridLink.DataBind();