Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all

How to change label text from another procedure (web c#).

My Label id is Label1
My procedure is Zipdownloadfile

Anybody can help me ?

Thank's in advance

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Threading;
using System.Text;
using System.IO;
using System.Net;
using Oracle.ManagedDataAccess.Client;
using System.Globalization;
using Ionic.Zip;

public partial class ACD_Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Zipdownloadfile(Main.ServerPath() + @"TempFile\Income_statement_AACS\Iqube", "sqmr");
    }

    public static string Zipdownloadfile(string pathdownload, string filenamezip)
    {
        var logerror = "";
        try
        {
            using (ZipFile zip = new ZipFile())
            {
                zip.AlternateEncodingUsage = ZipOption.AsNecessary;

                string[] ArrayFile = Directory.GetFiles(pathdownload);
                foreach (string NameFile in ArrayFile)
                {
                    zip.AddFile(NameFile, filenamezip);
                }

                System.Web.HttpContext.Current.Response.Clear();
                System.Web.HttpContext.Current.Response.BufferOutput = false;
                System.Web.HttpContext.Current.Response.ContentType = "application/zip";
                System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filenamezip + ".zip");
                zip.Save(System.Web.HttpContext.Current.Response.OutputStream);

                foreach (string NameFile in ArrayFile)
                {
                    File.Delete(NameFile);
                }

                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.SuppressContent = true;
                System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }
        catch (Exception ex)
        {
            logerror = ex.Message.ToString();
        }

        return logerror;
    }

}
Posted
Updated 25-Jul-18 23:52pm
v2

You can't change the label from that function, to update the html in the browser the response needs to send the updated html, but your response is sending a file. If you want the content of the page updated then you'll need to do it in javascript when the request to download the file is made. Note that this is done before the download, so you can't update the label after the download as you have no idea if or when the download has happened.
 
Share this answer
 
using out parameter in your mentord
 
Share this answer
 
Comments
Richard Deeming 26-Jul-18 12:18pm    
Utter nonsense. Read solution 2, which is the correct answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900