标签文字未更新 [英] label text not getting updated

查看:95
本文介绍了标签文字未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个asp.net上工作,该网站有2个用于生成文件的按钮.
只需单击一个按钮,我就会生成一个文件并为用户提供一个保存弹出窗口.
在其他按钮上,单击我生成文件"并将文件保存在本地计算机上.
每次单击按钮时,我需要更新数据库中的按钮单击时间,并使用标签在屏幕上显示最后一次按钮单击时间.
在每个按钮单击事件中,我都调用了UpdateTimeOnScreen()函数

UpdateTimeOnScreen()

函数中,我从数据库获取了上次按钮单击,并使用标签显示了该时间.
在一个将文件保存到计算机上的按钮上,时间正在屏幕上正确更新.
但是单击其他按钮(使用户弹出保存窗口)时,时间就不会更新.
我看到使用debug,上面的

UpdateTimeOnScreen()

被正确调用,并且在该函数中,时间也分配给了标签,但是在执行代码后

 // 清除响应的内容
                    Response.ClearContent();

                    // 将文件名和附件添加到标题中,这将强制打开/取消/保存对话框显示
                    Response.AddHeader(" " 附件; filename =" + fileName);

                    // 将文件大小添加到响应标题中
                    Response.AddHeader(" ,bufferDataArray.Length.ToString());

                    Response.ContentType = " ;

                    // 将文件写入响应(TransmitFile用于ASP.NET 2.0.在ASP.NET 1.1中,必须使用改为使用WriteFile)
                    Response.BinaryWrite(bufferDataArray);
                    // 结束响应
                    Response.End(); 



labeltext,将文本获取为"

[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

",并且标签中的时间未更新

解决方案

要代替Response.End,您必须使用HttpContext.Current.ApplicationInstance.CompleteRequest方法来绕过Application_EndRequest事件的代码执行. br/>
在此处查看详细信息: Microsoft支持:如果您使用Response.End,Response.Redirect或Server.Transfer,则会发生ThreadAbortException [ ^ ]

I m working on a asp.net which, which has 2 buttons to generate files.
on one button click i generate a file and give user a popup of save.
on other button click i generate file and save file on the local machine.
On each button click, i need to update the button click time in database and show last button click time on the screen using labels.
In each button click event, i have called UpdateTimeOnScreen() function
In

UpdateTimeOnScreen()

function, i fetch last time button click from databse and show that time using labels
On one button that saves files on machine, the time is getting properly updated on screen.
but on other button click, that gives user a popup of save, the time is not getting updated.
I saw using debug, the above

UpdateTimeOnScreen()

is called properly and in that function, time is also assigned to labels but after execution of the code

// Clear the content of the response
                    Response.ClearContent();

                    // Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);

                    // Add the file size into the response header
                    Response.AddHeader("Content-Length", bufferDataArray.Length.ToString());

                    Response.ContentType = "text/plain";

                    // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
                    Response.BinaryWrite(bufferDataArray);
                    // End the response
                    Response.End();



the labeltext , gets text as ''

[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

'' and time in the label is not getting updated

How to solve this issue?

解决方案

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest method to bypass the code execution to the Application_EndRequest event.

Look here for details: Microsoft Support: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer[^]


这篇关于标签文字未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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