Is it possible to implement to trigger an extra event/function when clicking the file links

2 posts, 0 answers
  1. Brent
    Brent avatar
    2 posts
    Member since:
    Nov 2013

    Posted 27 Nov 2013 Link to this post

    Hi Telerik,

    I use a radGridviews to implement a system which supports downloading files from IIS server.

    The column setting is shown below,
    <telerik:GridHyperLinkColumn DataTextField="File Name" HeaderText="File Name" UniqueName="File Name" DataNavigateUrlFormatString="IIS_ItemServer\{0}" DataNavigateUrlFields="File Path" />

    In addition to downloading files,

    is it possible to implement to trigger an extra event/function when clicking the file links by this way?

    Thanks you

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 29 Nov 2013 Link to this post

    Hi Brent,

    First I would like to point out that the UniqueName of a columns could not contain spaces, so you should rename the UniqueName of the column to "FileName".

    Now, moving to your requirement. For handling the click event on the GridHyperLinkColumn hyperlink you could handle the server-side ItemDataBound event, get reference to the HyperLink control of the column and add event handler for the client-side "onclick" event. Below is a sample example for adding the event handler:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            HyperLink button = item["FileName"].Controls[0] as HyperLink;
            button.Attributes.Add("onclick", "onHyperLinkClick()");
        }
    }
    And the JavaScript:
    <script type="text/javascript">
        function onHyperLinkClick() {
            // your custom logic
        }
    </script>

    Hope that helps.


    Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top