How to assign a callback function to asp: HyperlinkField?

I want people to click on a link (generated from asp: HyperlinkField) and call it on the server, rather than redirecting the user. Does anyone know how to do this?

Thanks
Matt

+3
source share
4 answers

I would use asp: CommandField or asp: ButtonField and use ButtonType = Link - which will look just like your link field, and then you can handle the OnRowCommand event in your grid to run your code.

+1
source

asp: LinkButton. , asp: Hyperlink?

+1

HyperLinkField . ButtonField. TemplateField.

, :

<asp:templatefield headertext="Link Column">
    <itemtemplate>
      <asp:LinkButton ID="myLink" 
            CommandName="MyLinkCommand" 
            CommandArgument='<%#Bind("TableID") %>'
            runat="server">My Link</asp:LinkButton>
    </itemtemplate>
</asp:templatefield>

:

protected void YouGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "MyLinkCommand")
    {
        // Do stuff
    }
}
+1

ButtonField ButtonType ? .

0

Source: https://habr.com/ru/post/1711369/


All Articles