Solved

Problems with showing label text

Posted on 2006-06-27
11
305 Views
Last Modified: 2010-08-05
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.
0
Comment
Question by:dentyne
  • 5
  • 5
11 Comments
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16992285
 function showMessage() {
         document.getElementById("message").innerText = "Downloading file......";
     }  
0
 
LVL 1

Author Comment

by:dentyne
ID: 16992301
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.
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16992352
message.Text = " "  will work
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16992387
private void downloadReport_ServerClick(object sender, System.EventArgs e)
{
     downloadFile(fileID,fileName.Text,contentType.Text,fileSize.Text);
      message.Text = "";
}
0
 
LVL 1

Author Comment

by:dentyne
ID: 16992442
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.  

0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16992501
try to use
message.Text = " ";
 Response.Flush();
Response.Close();
0
 
LVL 1

Author Comment

by:dentyne
ID: 16992553
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?
0
 
LVL 7

Assisted Solution

by:pradeepsudharsan
pradeepsudharsan earned 250 total points
ID: 16992674
<script language="javascript">
      function Clear()
            {
              document.getElementById("message").innerText="";
             
            }
      
            </script>

server side

oFileUp.TransferBlob(dr,0);
    String strScript ;
        strScript = "<script>";
        strScript += "Clear();";
        strScript += "</script>";
        Page.RegisterStartupScript("ClientScript", strScript);

        Response.Close();
       
0
 
LVL 1

Author Comment

by:dentyne
ID: 16992829
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.
0
 
LVL 5

Accepted Solution

by:
vinodhsomasekharan earned 250 total points
ID: 16999223
Hai,

 I think we can't trace the status of the  download dialog shown by the Internet Explorer....

regards
Vinodh
0
 
LVL 1

Author Comment

by:dentyne
ID: 17017247
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question