Link to home
Start Free TrialLog in
Avatar of dentyne
dentyne

asked on

Problems with showing label text

Hi experts,

I nonmodal pop up a window that loads an .aspx page that displays some data about a file.  The user clicks a button to download the file.  I want to be able to display a message in a label when they click the button like "Downloading...."  then when the download is done it would say "Download complete" or simply erase the downloading message.  I need this because sometimes it cranks away a bit after clicking the button and to the user it looks like it's doing nothing.

I was able to successfully do the first part by adding an onclick attribute to the server button, but for the life of me I can't figure out how to make it go away.  It seems to ignore all message.Text = "" commands.  Here is my code:

RELEVANT CODE FROM THE ASPX:
=======================
<head>
<script language="javascript">
     function showMessage() {
         document.getElementById("message").innerHTML = "Downloading file......";
     }            
</script>
</head>
.
.
.
<tr>
     <td colspan="2"><asp:Label ID="message" runat="server" /></td>
</tr>
<tr>
     <td colspan="2"><input ID="downloadReport" type="submit" value="Download" runat="server"></td>
</tr>

CODEBEHIND CODE:
=============
private void Page_Load(object sender, System.EventArgs e)
{
     downloadReport.Attributes.Add("onClick","return showMessage();");
}

private void downloadReport_ServerClick(object sender, System.EventArgs e)
{
     downloadFile(fileID,fileName.Text,contentType.Text,fileSize.Text);
}
private void downloadFile(int binID,string fileName, string contentType, string fileSize)  
{
    .
    .
    .
    conn.Open();
    cmd = new OracleCommand("SELECT blob from sometable where bin_id= :bin_id",conn);
    OracleParameter bin_id = cmd.Parameters.Add("bin_id",OracleDbType.Int64);
    bin_id.Value = binID;
    dr = cmd.ExecuteReader();
    Response.ContentType = contentType;
    Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", fileName));
    Response.AddHeader("Content-Length", fileSize);
    oFileUp.TransferBlob(dr,0);    
    Response.Close();
}


The oFileUp object above is the SoftArtisans FileUp, but I don't think that matters.  Anyway, when I click the button, the onClick attribute added in the Page Load correctly displays "Downloading file...."  in the label.  But I can't make this disappear.  I have tried:

-- Adding message.Text = "" after the TransferBlob method in the downloadFile function
-- Adding message.Text = "" after the call to downloadFile

I am at a loss.  Thanks for your help.
Avatar of pradeepsudharsan
pradeepsudharsan

 function showMessage() {
         document.getElementById("message").innerText = "Downloading file......";
     }  
Avatar of dentyne

ASKER

The showMessage() function works fine.  It displays the "Downloading file....." message when the server button is clicked.   My problem is making it disappear once the download is complete.
message.Text = " "  will work
private void downloadReport_ServerClick(object sender, System.EventArgs e)
{
     downloadFile(fileID,fileName.Text,contentType.Text,fileSize.Text);
      message.Text = "";
}
Avatar of dentyne

ASKER

Where do I put this message.Text = " "?  As stated in the problem, I tried blanking or changing the text by putting that line in the downloadFile function before the "Response.Close();" line.  I have also tried putting it in the downloadReport_ServerClick function after the call to downloadFile.  It does not work.  The file downloads and I still see "Downloading file......" on the screen.

Just to be clearer:

In the ServerClick method:
downloadFile(fileID,fileName.Text,contentType.Text,fileSize.Text);
message.Text = " ";


In the download file method:
message.Text = " ";
oFileUp.TransferBlob(dr,0);
message.Text = " ";
Response.Close();


The message still says "Downloading file...." when the Internet Explorer file download box appears.  Even after I download the file the message is still there.  

try to use
message.Text = " ";
 Response.Flush();
Response.Close();
Avatar of dentyne

ASKER

Unfortunately that didn't work either.  I tried putting it in all of the places.  Maybe it does have something to do with the FileUp control.  It just seems odd though.  Is there is a way to call a client javascript function after the TransferBlob method that would change it back?
SOLUTION
Avatar of pradeepsudharsan
pradeepsudharsan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dentyne

ASKER

This is pretty tough.  That script code you gave doesn't work.  But if I comment all all of the response header settings and the transferblob (as if I wasn't downloading), then it does work.  I think that when Internet Explorer gives that File Download box, that something damaging happens and I lose control.   It's pretty frustrating.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dentyne

ASKER

Thanks for all of the help.  I guess Vinodh is correct in that we can't trace the status of the download dialog.  That is unfortunate.  Pradeep your effort was outstanding and I learned a lot.  I hope you both think the point split is fair.