ตอนนี้เขียน asp.net อยู่ครับ แต่ไม่มีความเข้าใจเรื่อง callback ใน web เลย อยากรู้ขั้นตอนการทำงานของ callback ใน web มีใครพอจะอธิบายได้บ้างครับ รบกวนผู้รู้ด้วยครับ
Tag : ASP, HTML/CSS, JavaScript, Ajax, Web (ASP.NET), Web Service
Imports System.Web.UI
Public Class ICallbackEventHandler_js : Inherits System.Web.UI.Page : Implements ICallbackEventHandler
Protected returnValue As String
Protected catalog As ListDictionary
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
'Add Client Script Dynamically to ASP.NET Web Pages
Dim st As String = "return confirm('เมียเอ็งซวยไหม?')"
ClientScript.RegisterOnSubmitStatement(Page.GetType, "ConfirmSubmit", st)
End Sub
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim csm As ClientScriptManager = Page.ClientScript
Dim callBackReference As String = csm.GetCallbackEventReference(Page, "arg", "ReceiveServerData", "context")
Dim callBackScript As String = "function CallServer(arg, context) {" + callBackReference + "};"
csm.RegisterClientScriptBlock(Page.GetType(), "CallServer", callBackScript, True)
ListBox1.DataSource = DemoData()
ListBox1.DataTextField = "key"
ListBox1.DataBind()
End Sub
Protected Function DemoData() As ListDictionary
'' Populate List Dictionary with invented database data
catalog = New ListDictionary()
catalog.Add("monitor", 12)
catalog.Add("laptop", 10)
catalog.Add("keyboard", 23)
catalog.Add("หอยงาม", 25)
Return catalog
End Function
Public Function GetCallbackResult() As String Implements ICallbackEventHandler.GetCallbackResult
Return returnValue
End Function
Public Sub RaiseCallbackEvent(eventArgument As String) Implements ICallbackEventHandler.RaiseCallbackEvent
If catalog(eventArgument) Is Nothing Then
returnValue = "-1"
Else
returnValue = catalog(eventArgument).ToString()
End If
End Sub
End Class
SELECT mstTab.*, tmp1.Col1
FROM Human mstTab
OUTER APPLY (SELECT TOP 1 CASE WHEN Sex = '1' THEN 'ชาย' ELSE 'นั่งฉี่จ้า'' END Col1 FROM Human หอย WHERE หอย.sCode = mstTab.sCode) tmp1
WHERE tmp1.Col1 = 'นั่งฉี่จ้า'