如何从Web C#中的其他过程更改标签文本 [英] How to change label text from another procedure in web C#

查看:77
本文介绍了如何从Web C#中的其他过程更改标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



如何更改其他程序(web c#)的标签文字。



我的标签ID是Label1

我的程序是Zipdownloadfile



有人可以帮帮我吗?



提前感谢



我尝试过:



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data;
使用 System.Configuration;
使用 System.Data.SqlClient;
使用 System.Threading;
使用 System.Text;
使用 System.IO;
使用 System.Net;
使用 Oracle.ManagedDataAccess.Client;
使用 System.Globalization;
使用 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,< span class =code-string> sqmr);
}

public static string Zipdownloadfile( string pathdownload, string filenamezip)
{
var logerror = ;
尝试
{
使用(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 (例外情况)
{
logerror = ex.Message.ToString( );
}

return logerror;
}

}

解决方案

您无法将该标签从该功能更改为更新浏览器中的html响应需要发送更新的html,但您的响应是发送文件。如果您希望更新页面内容,那么在下载文件的请求时,您需要在javascript中执行此操作。请注意,这是在下载之前完成的,因此您无法在下载后更新标签,因为您不知道下载是否或何时发生。


在您的心理中使用out参数

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:

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

}

解决方案

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.


using out parameter in your mentord


这篇关于如何从Web C#中的其他过程更改标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆