Solved

Problems with showing label text

Posted on 2006-06-27
11
273 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
Comment Utility
 function showMessage() {
         document.getElementById("message").innerText = "Downloading file......";
     }  
0
 
LVL 1

Author Comment

by:dentyne
Comment Utility
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
Comment Utility
message.Text = " "  will work
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

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

Author Comment

by:dentyne
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now