Solved

Problems with showing label text

Posted on 2006-06-27
11
283 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

22 Experts available now in Live!

Get 1:1 Help Now