Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

asp.net - TextBox's text not changing in from upload_complete event handler

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...