Question

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

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?

Était-ce utile?

La solution

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. this workaround and a lot of other you can find in the AjaxControlToolkit sample site available for download from codeplex

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top