Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET手动更新updatepanel以在长函数中显示反馈_C#_Javascript_Asp.net_Updatepanel - Fatal编程技术网

C# ASP.NET手动更新updatepanel以在长函数中显示反馈

C# ASP.NET手动更新updatepanel以在长函数中显示反馈,c#,javascript,asp.net,updatepanel,C#,Javascript,Asp.net,Updatepanel,我有一个网站,有一个代码隐藏文件和一个单独的类,有一个功能,需要很长时间才能完成。 我想要的是在函数传递字符串时向访问者显示一些信息 我使用委托将字符串发送回代码,如下所示: public event Feedback feedbackInfo; public EventArgs e = null; public delegate void Feedback(String message, bool info); 因此,在我的函数中,我可以使用反馈信息(“message”,true)由代码隐藏

我有一个网站,有一个代码隐藏文件和一个单独的类,有一个功能,需要很长时间才能完成。 我想要的是在函数传递字符串时向访问者显示一些信息

我使用委托将字符串发送回代码,如下所示:

public event Feedback feedbackInfo;
public EventArgs e = null;
public delegate void Feedback(String message, bool info);
因此,在我的函数中,我可以使用
反馈信息(“message”,true)由代码隐藏功能setFeedback接收:

public void example() {
    new Thread(delegate()
                {
                    crypto = new EncryptNoLibraries(@"C:\Users\Robbie\TestDES\New Microsoft Visio Drawing.vsdx", @"C:\Users\Robbie\TestDES\New Microsoft Visio Drawing encrypted.vsdx");
                    crypto.feedbackInfo += new EncryptNoLibraries.Feedback(setFeedback);

                    object[] allArgs = { EncryptNoLibraries.CryptType.ENCRYPT, lstSleutels };
                    object args = allArgs;
                    crypto.DoCryptFile(args);
                }).Start();
}

public void setFeedback(String message, bool info)
{
    if (info)
    {
        if (!infoCell.Visible)
        {
            errorCell.Visible = false;
            infoCell.Visible = true;
        }
        lblInfo.Text += String.Format("- {0}<br />", message);
    }
    else
    {
        if (!errorCell.Visible)
        {
            infoCell.Visible = false;
            errorCell.Visible = true;
        }
        lblError.Text += String.Format("- {0}<br />", message);
    }
}
public void示例(){
新线程(委托()
{
crypto=新加密库(@“C:\Users\Robbie\TestDES\new Microsoft Visio Drawing.vsdx”,@“C:\Users\Robbie\TestDES\new Microsoft Visio Drawing encrypted.vsdx”);
crypto.feedbackInfo+=新的EncryptLibraries.Feedback(设置反馈);
对象[]allArgs={EncryptNoLibraries.CryptType.ENCRYPT,lstslutels};
对象args=allArgs;
加密文件(args);
}).Start();
}
公共无效设置反馈(字符串消息、布尔信息)
{
如果(信息)
{
如果(!infoCell.Visible)
{
errorCell.Visible=false;
infoCell.Visible=true;
}
lblInfo.Text+=String.Format(“-{0}
”,消息); } 其他的 { 如果(!errorCell.Visible) { infoCell.Visible=false; errorCell.Visible=true; } lblError.Text+=String.Format(“-{0}
”,消息); } }
这是我的网页:

<%@ Page Title="Home" Async="true" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DESEncryptie._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
    <script type="text/javascript">

        function updater() {
            __doPostBack('updatePanel', '');
        }
    </script>
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>DES encryptie/decryptie</h1>
            </hgroup>
            <p>
                Kies simpelweg uw bestand. Vervolgens kiest u uw sleutel en de methode van encryptie of decryptie. Als laatste kiest u de taal waarmee u wilt werken (bijv. Java of .NET).
            </p>
        </div>
    </section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <h3>Start hier:</h3>
    <asp:UpdatePanel ID="updatePanel" runat="server">
        <ContentTemplate>
            <asp:Table runat="server" CssClass="tableStartHier">
                <asp:TableRow>
                    <asp:TableCell>Bestand:</asp:TableCell>
                    <asp:TableCell>
                        <asp:FileUpload ID="bestand" runat="server" on />
                        <i>(Probleem: bestandsnamen kunnen te lang zijn)</i>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell><asp:CheckBox ID="DES" runat="server" Checked="true" TextAlign="Left"
                        Text="DES" OnCheckedChanged="DES_CheckedChanged" AutoPostBack="true" /></asp:TableCell>
                    <asp:TableCell><asp:CheckBox ID="ThreeDES" runat="server" Checked="false" TextAlign="Left"
                        Text="3DES" OnCheckedChanged="ThreeDES_CheckedChanged" AutoPostBack="true" /></asp:TableCell>
                </asp:TableRow>

                <asp:TableRow>
                    <asp:TableCell ColumnSpan="2">Sleutel:</asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="sleutelDES" runat="server" Visible="true">
                    <asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel" runat="server" placeholder="Geef een sleutel" /></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="sleutelDrieDES1" runat="server" Visible="false">
                    <asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel1" runat="server" placeholder="Geef sleutel 1" /></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="sleutelDrieDES2" runat="server" Visible="false">
                    <asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel2" runat="server" placeholder="Geef sleutel 2" /></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="sleutelDrieDES3" runat="server" Visible="false">
                    <asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel3" runat="server" placeholder="Geef sleutel 3" /></asp:TableCell>
                </asp:TableRow>

                <asp:TableRow>
                    <asp:TableCell>Taal:</asp:TableCell>
                    <asp:TableCell>
                        <asp:DropDownList ID="taal" runat="server" Width="75px">
                            <asp:ListItem Text=".NET" Value=".NET" />
                            <asp:ListItem Text=".NET Libraries" Value=".NETLib" />
                            <asp:ListItem Text="Java Libraries" Value="Java" />
                        </asp:DropDownList>
                    </asp:TableCell>
                </asp:TableRow>

                <asp:TableRow>
                    <asp:TableCell><asp:Button id="encrypteer" Text="Encrypteer" runat="server" OnClientClick="setInterval(updater, 2500);" OnClick="encrypteer_Click" ToolTip="Encrypteer uw bestand" /></asp:TableCell>
                    <asp:TableCell><asp:Button id="decrypteer" runat="server" Text="Decrypteer" OnClick="decrypteer_Click" ToolTip="Decrypteer uw bestand" /></asp:TableCell>
                </asp:TableRow>

                <asp:TableRow>
                    <asp:TableCell runat="server" ID="spinner" Visible="false">
                        <asp:Image ID="imgSpinner" runat="server" ImageUrl="~/Images/spinner.gif"/>Even geduld.
                    </asp:TableCell>
                </asp:TableRow>

                <asp:TableRow ForeColor="Blue">
                    <asp:TableCell ID="infoCell" runat="server" ColumnSpan="2" Visible="false">
                        Informatieberichten tijdens het crypteren:<br />
                        <asp:Label ID="lblInfo" runat="server" Text="" />
                    </asp:TableCell>
                </asp:TableRow>

                <asp:TableRow ForeColor="Red">
                    <asp:TableCell ID="errorCell" runat="server" ColumnSpan="2" Visible="false">
                        Foutberichten tijdens het crypteren:<br />
                        <asp:Label ID="lblError" runat="server" Text="" />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

函数更新程序(){
__doPostBack('updatePanel','';
}
DES加密/解密

Kies simpelweg uw bestand。Vervolgens是decryptie的加密方法。Als laatste kiest u de taal waarmee u wilt werken(bijv.Java of.NET)。

起始层次: 最佳和: (问题:贝斯坦·斯纳曼·库宁·特朗兹) 斯卢特尔: 塔尔: 甚至格杜德。 地下室的信息:
福特伯里希登·蒂登斯·赫特·克里特伦:
您可以看到我使用javascript每2.5秒回发一次来更新我的面板。问题在于,当触发回发时,标签中应更新的文本将丢失。 下面是一些图片来说明。Before是页面在第一次渲染时的外观,after是我按下encrypt按钮后显示的内容。即使在2.5秒后,也不会显示所有消息(它们甚至会消失!)

之前:

之后:


我做错了什么?

我想这是我的错,我找到了解决办法。 到目前为止,我添加了两个保存消息的静态字符串变量

private static String infoMessages = "", errorMessages = "";
public void setFeedback(String message, bool info)
{
    if (info)
    {
        if (!infoCell.Visible)
        {
            errorCell.Visible = false;
            infoCell.Visible = true;
        }
        infoMessages += String.Format("- {0}<br />", message);
        lblInfo.Text += infoMessages;
    }
    else
    {
        if (!errorCell.Visible)
        {
            infoCell.Visible = false;
            errorCell.Visible = true;
        }
        errorMessages += String.Format("- {0}<br />", message);
        lblError.Text += errorMessages;
    }
}
私有静态字符串infoMessages=“”,errorMessages=“”;
公共无效设置反馈(字符串消息、布尔信息)
{
如果(信息)
{
如果(!infoCell.Visible)
{
errorCell.Visible=false;
infoCell.Visible=true;
}
infoMessages+=String.Format(“-{0}
”,message); lblInfo.Text+=infoMessages; } 其他的 { 如果(!errorCell.Visible) { infoCell.Visible=false; errorCell.Visible=true; } errorMessages+=String.Format(“-{0}
”,message); lblError.Text+=错误消息; } }
我认为ASP.Net网页对象不会在文章之间持久存在。它们将从会话存储中重新创建和填充

在我的代码中,我有一个对应用程序全局的后台操作。我能够使用类中的一些静态成员将后台任务的进度传递给用户

我使用ASP计时器获取回发:

Timer1\u Tick方法中没有代码。只是一条注释,说明页面加载完成了与显示进度相关的工作

您的情况将更加困难,因为您可以为每个浏览器实例执行一个后台任务

如果使用由会话id键入的静态成员词典,后台进程可以更新词典条目,页面加载可以更新用户屏幕

然后是会议来来去去的问题。你如何整理这样一本词典

另外,请记住,IIS往往会在20分钟没有http请求后关闭整个网站进程


[当我输入详细的答案时,你似乎自己也找到了。表演得好!]

谢谢你的贡献!我不知道IIS关闭了20分钟