TextBox的文本没有从upload_complete事件处理程序中更改

时间:2012-08-23 17:26:08

标签: asp.net vb.net ajaxcontroltoolkit asyncfileupload

我在AsyncFileUpload的上传完成事件处理程序中有以下代码:

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调试了它,并且使用了线条tns.text ...来调试它,我在手表中得到了正确的值。那么我该如何绕过呢?

1 个答案:

答案 0 :(得分:0)

使用以下代码替换tns.TextAsyncFileUpload1_UploadedComplete属性的设置:

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。您可以在AjaxControlToolkit示例站点中找到此解决方法以及许多其他可从codeplex下载的示例站点