This is a migrated thread and some comments may be shown as answers.

Refreshing RadGrid after downloading file via ashx

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 13 Apr 2012, 08:01 PM
I have a grid with a column that shows whether a file has been downloaded or not (via an image in a grid column)

When the user clicks the Checkout toolbar button, I call an .ashx file, which downloads the file to the user's desktop and updates the the database that the file's been checked out.  The issue I'm having is that when I try and refresh the grid by calling the grid.rebind method (on either the client or server side), not all the logic in the .ashx file gets executed (well, the database is updated, but the file isn't downloaded).

How can I refresh the grid on the client side after *successfully* calling the ashx method (where successfully means the file is downloaded *and* the database is updated)?

Here's the relevant code:

function CheckOut(){
 
    var isExternal = false;
    var rgGrid = $find("<%= rgAttachmentVersion.ClientID %>");
 
    if ( rgGrid._selectedIndexes[0] == null ) {
        rgGrid = $find("<%= rgExternalAttachment.ClientID %>");
        isExternal = true;
    }
 
    var selectedVersionId;
    if ( isExternal ) {
        selectedVersionId = rgGrid._clientKeyValues[rgGrid._selectedIndexes[0]].ID + "&isExternal=true";
    } else if ( rgGrid._selectedIndexes[0].indexOf(":") > 0 ) {
        selectedVersionId = rgGrid._clientKeyValues[rgGrid._selectedIndexes[0]].ID;
    } else {
        selectedVersionId = rgGrid.MasterTableView.getCellByColumnUniqueName(rgGrid.MasterTableView.get_dataItems()[rgGrid._selectedIndexes[0]], "OpenVersion").innerHTML;
    }
         
    var finalUrl = "~/VersionCheckoutHandler.ashx?id=" + selectedVersionId + "&callback=false" + "&rand=" + Math.random(); // add random number to make sure the browser does nto cache it
    var xhReq = new XMLHttpRequest();
    xhReq.open("GET",$Url.resolve(finalUrl),false);
    xhReq.send(null);
             
    if ( xhReq.responseText == "FILEDOWNLOADERROR" )
    {
        alert("An error has occurred. Please contact your system administrator.");
    }
    else if ( xhReq.responseText == "VERSIONALREADYCHECKEDOUT")
    {
        alert("This version is currently checked out.");
        refreshAttachmentList();
    }
    else if ( xhReq.responseText == "UNABLETOCHECKOUTREMOTEREPOSITORY")
    {
        alert("This version is unable to be checked out from the remote repository.");
    }
    else
    {
        triggerIsPostBack = true;
        window.location = $Url.resolve("~/VersionCheckoutHandler.ashx?id=" + selectedVersionId + "&callback=true");
        triggerIsPostBack = false;       
    }
}


I have a client-side call that rebinds the grid (below) successfully from other methods, but when I call that after calling the CheckOut function, the file isn't saved locally (even though the grid rebinds).

function refreshAttachmentList() {
    try{displayLogoffWarning = false;} catch(ex) {}
    try {
        $find("<%= rgAttachmentVersion.MasterTableView.ClientID %>").fireCommand('<%=RadGrid.RebindGridCommandName %>');
    } catch (ex) { }
    try {
        $find("<%= rgExternalAttachment.MasterTableView.ClientID %>").fireCommand('<%=RadGrid.RebindGridCommandName %>');
    } catch (ex) { }
 
}

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 19 Apr 2012, 12:35 PM
Hello Matt,

I am not sure if the XMLHttpRequest triggers some event when the transfer is over, you could research for this in the web, since it is a more generous question and not related to our controls.
Additionally you may rebind the grid with some timer constantly, or just rebind it after some timeout, if you know how many time will be needed for the transfer.

Kind regards,
Vasil
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or