简体   繁体   English

如何拦截来自datagrid的超链接点击?

[英]How can I intercept hyperlink click from datagrid?

Right now I have a datagrid with a template column as follows: 现在我有一个带有模板列的数据网格,如下所示:

<asp:TemplateColumn> <ItemTemplate> <asp:HyperLink ID="lnkSelect" runat="server" Target="_blank" /> </ItemTemplate></asp:TemplateColumn>

The OnItemDataBound method builds the NavigateURL property of the Hyperlink dynamically, based on another column in this datagrid, which contains a GUID. OnItemDataBound方法基于此数据网格中包含GUID的另一列,动态构建Hyperlink的NavigateURL属性。 Selecting a row by clicking on the hyperlink brings up a Dynamics CRM web page for the Contact with that GUID. 通过单击超链接选择一行,将打开带有该GUID的联系人的Dynamics CRM网页。 This program is launched from a ribbon button click in CRM, via a JScript. 该程序是通过JScript在CRM中单击功能区按钮启动的。

This system works fine but I find I now need to intercept that click event. 该系统运行良好,但我现在需要拦截该click事件。 I tried adding a OnSelectedIndexChanged event but this was ignored; 我尝试添加一个OnSelectedIndexChanged事件,但是该事件被忽略了。 execution did not seem to stop there. 执行似乎并没有就此停止。

Is there any way to intercept the hyperlink click, or, conversely, is there another control I can use that will allow building dynamic URLs and also interception of a click event? 有没有办法拦截超链接的点击,或者相反,有没有我可以使用的另一种控件,它可以构建动态URL并也可以拦截click事件?

Thank you. 谢谢。

You will have to do this on client, specifically in "onclick" event. 您将必须在客户端上执行此操作,特别是在“ onclick”事件中。

Create a JavaScript function, eg clickIntercept() that would perform nessessery operations befor navigation; 创建一个JavaScript函数,例如clickIntercept() ,它将在导航之前执行nessessery操作; then in the code where you assign NavigateURL property assign "onclick" attribute with the value of "clickIntercept". 然后在您分配NavigateURL属性的代码中,为“ onclick”属性分配“ clickIntercept”值。

Thank you for your response, Trekstuff. 谢谢您的回应,Trekstuff。

I also found that I could change my hyperlink to a ButtonColumn, remove the OnItemDataBound code and use an OnItemCommand method instead. 我还发现我可以将超链接更改为ButtonColumn,删除OnItemDataBound代码,而改用OnItemCommand方法。

For the OnItemCommand I have: 对于OnItemCommand,我有:

switch (((LinkButton)e.CommandSource).CommandName)
     {
            case "Select":    
               String selectedContact = ServerURL + QueryStringPrefix + e.Item.Cells[1].Text + QueryStringSuffix;
               Response.Redirect(selectedContact); 
               break;
     }

This works for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM