Member 13574900 Ответов: 2

Как изменить текст метки из другой процедуры в web C#


Дорогие все

Как изменить текст метки из другой процедуры (web c#).

Мой идентификатор этикетки Label1
Моя процедура-Zipdownloadfile

Кто-нибудь может мне помочь ?

Заранее спасибо

Что я уже пробовал:

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;
    }

}

2 Ответов

Рейтинг:
2

F-ES Sitecore

Вы не можете изменить метку из этой функции, чтобы обновить html в браузере, ответ должен отправить обновленный html, но ваш ответ отправляет файл. Если вы хотите обновить содержимое страницы, то вам нужно будет сделать это в javascript, когда будет сделан запрос на загрузку файла. Обратите внимание, что это делается до загрузки, поэтому вы не можете обновить метку после загрузки, так как понятия не имеете, произошла ли загрузка или когда она произошла.


Рейтинг:
2

Member 11621026

использование параметра out в вашем наставнике


Richard Deeming

Сущие пустяки. Прочитайте решение 2, которое является правильным ответом.