文本框的文本不会从upload_complete事件处理程序改变 [英] TextBox's text not changing in from upload_complete event handler

查看:129
本文介绍了文本框的文本不会从upload_complete事件处理程序改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code在AsyncFileUpload的上传完整的事件处理程序:

I have the following code in AsyncFileUpload's upload complete event handler:

Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFileUpload1.UploadedComplete

    Dim oapp As Excel.Application
    Dim oWBa As Excel.Workbook
    Dim oWS As Excel.Worksheet
    Dim oRng As Excel.Range
    oapp = New Excel.Application
    AsyncFileUpload1.PostedFile.SaveAs(Server.MapPath("tempfile2.xlsx"))
    oWBa = oapp.Workbooks.Open(Server.MapPath("tempfile2.xlsx"))
    oWS = DirectCast(oWBa.Worksheets(2), 
    Excel.Worksheet)
    'Here tns is a textbox contained in a panel
    tns.Text = Integer.Parse(oWS.Range("W44").Value) + Integer.Parse(oWS.Range("W55").Value)
    oWBa.Close()

    File.Delete(Server.MapPath("tempfile2.xlsx"))
End Sub

TNS的AutoPostBack属性被打开,为什么当一个文件被上传它不会改变它的文字?也没有在读取Excel文件的逻辑错误的问题,因为我一直在使用VS 2010和Uptil行tns.text ......,我得到了watch.So正确的值我应如何轮得到它调试呢?

The autopostback property of tns is turned on so why does it not change its text when a file is uploaded? Also there is no question of error in logic of reading the excel file because I have debugged it using VS 2010 and Uptil the line tns.text..., I get the correct value in the watch.So how shall I get round it?

推荐答案

AsyncFileUpload1_UploadedComplete tns.Text 属性设置C>低于code:

Replace setting of tns.Text property in AsyncFileUpload1_UploadedComplete with code below:

var resultString = Integer.Parse(oWS.Range("W44").Value) + Integer.Parse(oWS.Range("W55").Value);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "result", "top.$get(\"" + tns.ClientID + "\").value = '" + resultString + "';", true);

P.S。此解决方法和很多其他的你可以可以从codePLEX

P.S. this workaround and a lot of other you can find in the AjaxControlToolkit sample site available for download from codeplex

这篇关于文本框的文本不会从upload_complete事件处理程序改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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