c# - Need to refresh a page.. logical problem

Joined
Dec 6, 2007
Messages
2
Reaction score
0
Hi, i've a simple problem. A minor bug in fact..
I have a page with mp3 listing and a column showing the amount of time a download button has been hit. the code works as follow :

Mp3main.aspx.cs
Page_Load :
GetMp3Info();
BuildTable();

//in BuildTable, I add a button dynamically to each row with a specific ID for the download. When we click on the button, I fire the Download_Click() event. Everything is still alright here.

Code:
        private void Download_Click(object sender, ImageClickEventArgs e)
        {
            const string strDown = "download";
            string imageID = ((ImageButton)sender).ID; 
            imageID = imageID.Substring(strDown.Length, imageID.Length - strDown.Length);

            string user = imageID.Substring(0, imageID.IndexOf("-"));
            string nomFichier = imageID.Substring(user.Length + 1, imageID.Length - user.Length - 1);

            IncrémenterDownload(user, nomFichier);
            
            Response.Redirect("download.aspx" + "?fichier=/music/" + user + "/" + nomFichier);
        }

It's all easy the cheesy. I get the ID, format the string. Send info to the url up to my download page.

The download page :

Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            string filepath = Request.QueryString["fichier"];

            if (filepath != null)
            {
                string fullfilepath = Server.MapPath("~/" + filepath);
                FileInfo download = new FileInfo(fullfilepath);
                if (download.Exists)
                {
                    Response.ClearContent();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + '"' + download.Name + '"');
                    Response.AddHeader("Content-Length", download.Length.ToString());
                    Response.ContentType = "audio/";
                    Response.WriteFile(download.FullName);
                    Response.End();
                    //Response.Redirect("mp3uloadmain.aspx"); DOESN'T WORK
                }
                else
                    lbl_download.Text = "OOPS! Le fichier n'existe plus!";
            }
            else
                lbl_download.Text = "Faut pas esseyer de m'entourlouper...";
        }

Okay! So mp3s get listed. download buttons are alright. down_click is fired upon click. Download manager popsup both in IE and FF. songs gets downloaded without having the user to change page. At least he doesn't know about it. Problem : The page won't reload itself at all to reload the amount of downloaded times for a mp3!

Why? Page_Load of mp3main.aspx.cs gets fired BEFORE my download_click event! so it has already built the table :S

If you want a live exemple of what i'm trying to say :
Mp3ULoad
I warn you, it's in french. use account aa/aa and play around as you wish
you'll get in the mp3main as soon as you login. if not, you click on new user :p

thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top