Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:08:47+00:00 2026-06-14T17:08:47+00:00

In my Asp page, i have to invoke one javascript function just before download

  • 0

In my Asp page, i have to invoke one javascript function just before download a file in asp page. My actual requirement is i have to make sure that the downloading format whenever click the download button.

So, In my download button event i just show a div tag that contains two radio buttons(asp:RadioButton) namely docx,pdf and also one OK button.after selecting any radio button, the user will press ok Button(asp:Button).

Finally,

In the Ok Button(asp:Button) event i just hide the div tag portion and the based on the selected output format user selected,the file will be downloading.

my Ok Button event Code is given below:

   protected void OKButton(object sender, EventArgs e)
    {
        string outputType = "";
        if (docx.Checked == true)
        {
            outputType = "docx";
        }
        else
        {
            outputType = "pdf";
        }

        filename=filename+"."+outputType;
       ClientScript.RegisterStartupScript(GetType(), "popup", "hidePopUp()", true);
       bool isDownloaded=downloadFile(strURL, docPath, filename);
    }

downloadFile function is given below:

protected bool downloadFile(string srcURL, string docPath, string filenameOnly)
        {
            System.IO.FileInfo FileName = new System.IO.FileInfo(srcURL);
            FileStream myFile = new FileStream(srcURL, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader _BinaryReader = new BinaryReader(myFile);

            if (FileName.Exists)
            {
                try
                {
                    long startBytes = 0;
                    string lastUpdateTiemStamp = File.GetLastWriteTimeUtc(docPath).ToString("r");
                    string _EncodedData = HttpUtility.UrlEncode(filenameOnly, Encoding.UTF8) + lastUpdateTiemStamp;

                    Response.Clear();
                    Response.Buffer = false;
                    Response.AddHeader("Accept-Ranges", "bytes");
                    Response.AppendHeader("ETag", "\"" + _EncodedData + "\"");
                    Response.AppendHeader("Last-Modified", lastUpdateTiemStamp);
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name);
                    Response.AddHeader("Content-Length", (FileName.Length - startBytes).ToString());
                    Response.AddHeader("Connection", "Keep-Alive");
                    Response.ContentEncoding = Encoding.UTF8;

                    //Send data
                    _BinaryReader.BaseStream.Seek(startBytes, SeekOrigin.Begin);

                    //Dividing the data in 1024 bytes package
                    int maxCount = (int)Math.Ceiling((FileName.Length - startBytes + 0.0) / 1024);

                    //Download in block of 1024 bytes
                    int i;
                    for (i = 0; i < maxCount && Response.IsClientConnected; i++)
                    {
                        Response.BinaryWrite(_BinaryReader.ReadBytes(1024));
                        Response.Flush();
                    }
                    //if blocks transfered not equals total number of blocks
                    if (i < maxCount)
                        return false;
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
                finally
                {
                   _BinaryReader.Close();
                    myFile.Close();
                }
            }
            else
            {
                return false;
            }

        }//downloadFile ends here...

Here, The particullar file downloaded successfully. But it did not hide the Div Tag Portion.

i tried without invoking the downloadFile function then it will hide the div tag portion successfully.

But i have to first hide the div tag portion and then download the particular file.Kindly refer my image also…

enter image description here

Please guide me to get out of this issue…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:08:49+00:00Added an answer on June 14, 2026 at 5:08 pm

    Why not hide the Div in your OKButton’s ClientClick.

    For example:

    <asp:Button ID="OkButton" runat="server" .... OnClick="OkButton_Click"
            OnClientClick="document.getElementById('divName').style.display = 'none';" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple asp page with a script including a function myFunction which
I have 6 text boxes on an asp page and one search button. Users
I have an ASP.Net page that has a script:# var Show; $(document).ready(function () {
In code-behind of an ASP.NET page I have this method: public string TestFunc() {
I have an asp page in which the are number of listboxes.I want to
I have the following ASP page: <asp:Content ID=Content2 ContentPlaceHolderID=ShellContent runat=server> <form runat=server id=AddNewNoteForm method=post>
I have an asp page that loads a response user=exists everytime I try to
I have an ASP page which displays a text box when it loads. It
I have a ASP Page and it has so many date variables. myvariable =
I have asp label in my asp page and its text is some my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.