Click to See Complete Forum and Search --> : code sample required


Bill Crawley
March 6th, 2007, 04:07 AM
Does anyone have a sample or link to a sample that shows how to update a label control Asyncronously. The only examples that I can find all want to sync back to another webpage.

Charu0306
March 7th, 2007, 01:29 AM
Use a thread or a delegate. Plenty of examples in MSDN.

Charu0306
March 7th, 2007, 01:32 AM
Sorry, if you are looking for asynchronous updates, in AJAX its possible using UpdatePanel to post back to the server or to set the status. Could set an Update trigger inside the UpdatePanel tag.

Simple example : http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

Bill Crawley
March 7th, 2007, 02:40 AM
I've followed Some samples, but none of them seem to work.

Here's the latest, I cant see what I'm doing wrong but it doesn't work. In all exmples, it's not clear when or how the Update is made. My attempt at trigerring the callback is within clsDTS_ScreenMessage when the value changed, I thought this would trigger the propogation back to the screen but it doesnt. I'm not trying to post back to the server, rather the server post up to the client messages at various stages from the clsDTS.Main Routine.

so in the aspx Head Section

<script type="text/javascript">
function ReceivedMessage(arg,EvalMessage)
{
document.getElementById("lblMessage").innerText = arg;
}
function GetMessage()
{
CallServer();
}
</script>


in the aspx.vb page I have:

Implements ICallbackEventHandler

Protected WithEvents clsDTS As New clsDTS()
Private strCallbackInvocation As String

Protected Sub btnCapture_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCapture.Click
clsDTS.Main()
End Sub

Protected Sub clsDTS_ScreenMessage(ByVal strMessage As String) Handles clsDTS.ScreenMessage
strCallbackInvocation = strMessage
End Sub


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cs As ClientScriptManager = Page.ClientScript
Dim Cb As String
Cb = cs.GetCallbackEventReference(Me, "arg", "ReceivedMessage", "EvalMessage", True)
Dim CallbackScript As String
CallbackScript = "function CallServer(arg, EvalMessage) {" & Cb & "; }"
cs.RegisterClientScriptBlock(Me.GetType(), "CallServer", CallbackScript, True)
Dim sJavaScript As String = ""
sJavaScript = "if (typeof(Page_ClientValidate) == 'function') { "
sJavaScript += "if (Page_ClientValidate() == false) { return false; }} "
sJavaScript += "this.value = 'Please wait...';"
sJavaScript += "this.disabled = true;this.style.cursor = 'wait';GetMessage();"
sJavaScript += cs.GetPostBackEventReference(btnCapture, "")
sJavaScript += ";"
btnCapture.Attributes.Add("onClick", sJavaScript)

End Sub

Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return strCallbackInvocation
End Function

Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
strCallbackInvocation = eventArgument
End Sub

aje33
March 17th, 2007, 03:08 PM
see http://www.codestreet.com/