Last post Dec 29, 2009 09:17 PM by Song-Tian - MSFT
Dec 23, 2009 10:27 PM|aspcheetah|LINK
Hi, Here is my code. I am trying to update UI (label control) from the callback method (ResultCallBack). However, nothing happens, that is, UI is not updated if I do something like label1.text=results. (Probably because page has already rendered????)???
So, my question is, what techniques are available to update the UI from the callback method?
Also, how to set session variable in callback method. Right now, if i do httpcontext.current.session("complete")=1 in the callback method, I get that sessionstate must be enabled in web.config or page level. However, session state is enabled - which I tested
by assigning session variable in page_load handler.
So, 2nd question, how to use session from callback method?
Partial Class test2
'Private Delegate Sub AppendAllTextDelegate(ByVal path As String, ByVal content As String)
Private Delegate Sub AppendAllTextDelegate()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
IO.File.AppendAllText("d:\log2.txt", ControlChars.CrLf & System.DateTime.Now() & "--" & "Page_Loaded on thread: " & Threading.Thread.CurrentThread.GetHashCode().ToString())
Dim myDelegateInstance As New AppendAllTextDelegate(AddressOf AppendAllTextBackground)
Dim myCallBackInstance As New AsyncCallback(AddressOf ResultCallBack)
' myDelegateInstance.BeginInvoke("d:\log2.txt", ControlChars.CrLf & System.DateTime.Now & "--" & "File Operation Complete on thread: " & Threading.Thread.CurrentThread.GetHashCode().ToString(), myCallBackInstance, myDelegateInstance)
'Private Sub AppendAllTextBackground(ByVal path As String, ByVal content As String)
' IO.File.AppendAllText(path, content)
Private Sub AppendAllTextBackground()
IO.File.AppendAllText("d:\log2.txt", ControlChars.CrLf & System.DateTime.Now & "--" & "File Operation Complete on thread: " & Threading.Thread.CurrentThread.GetHashCode().ToString())
Private Sub ResultCallBack(ByVal ar As IAsyncResult)
Dim myDelegateInstance As AppendAllTextDelegate = CType(ar.AsyncState, AppendAllTextDelegate)
update UI after callback
Dec 28, 2009 01:50 AM|Song-Tian - MSFT|LINK
In asp.net 2 making a client callback is a 4 step process:
2. The data accessed in step 1 will be sent to the server side function which will process the data, for that you need a client side fucntion which will call that server side method asynchronously.
3. The server method called asynchronously in step 2 will now process the data and then return the some result back to the client.
You could update UI (label control) from the callback method as that. And session as same.
For more details, please refer:http://www.themastech.net/Tutorials/ClientCallbacks/Default.aspx
Dec 28, 2009 07:32 PM|aspcheetah|LINK
But how would i do it in the code shown in my first post
I dont want to use icallbackeventhandler - which is what i think you are talking about.
Dec 29, 2009 12:45 AM|Song-Tian - MSFT|LINK
You could change your code and use icallbackeventhandler. That will be easy to do.
Dec 29, 2009 11:46 AM|aspcheetah|LINK
Thanks. So is there no other way besides icallbackeventhandler to achieve what i have asked for in my first post?
Dec 29, 2009 09:17 PM|Song-Tian - MSFT|LINK
Beside that, you could use ajax to implement.