Public Class WebForm4
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler
Public dic As Dictionary(Of String, String)
Private returnValue As String
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cbReference As String
cbReference = Page.ClientScript.GetCallbackEventReference(Me, _
"args", "Success", "", "Error", False)
Dim callbackScript As String = ""
callbackScript &= "function CallServer(args, context) { " & _
cbReference & "} ;"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), _
"CallServer", callbackScript, True)
End Sub
Protected Sub txt_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txt.TextChanged
'Page.ClientScript.RegisterStartupScript(Me.GetType(), "after", "alert('aaaaa');", True)
'Page.ClientScript.RegisterStartupScript(Me.GetType(), "", "confirm('确认吗?');", True)
'Page.ClientScript.RegisterStartupScript(Me.GetType(), "confirm", "CallServer(confirm(确认吗?),null);", True)
If Me.txt.Text = "" Then
Return
ElseIf Me.txt2.Text <> "" AndAlso Me.txt.Text = Me.txt2.Text Then
Me.txt2.Text = ""
Return
End If
Me.txt.Text = ""
Me.txt1.Text = ""
Me.txt2.Text = ""
Page.ClientScript.RegisterStartupScript(Me.GetType(), "confirm", "CallServer(confirm('确认吗?'),null);", True)
End Sub
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
dic = New Dictionary(Of String, String)
dic.Add("true", Confirm())
dic.Add("false", Cancel())
'If eventArgument = "false" Then
' Me.txt.Text = ""
' Me.lblName.Text = ""
'Else
' Me.txt1.Text = "aaaaaabbbbbb"
' Me.lblName.Text = "afasdgasdg" & eventArgument
'End If
returnValue = dic(eventArgument)
End Sub
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return returnValue
End Function
Public Function Confirm() As String
Return "Confirm"
End Function
Public Function Cancel() As String
Return "Cancel"
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'Page.ClientScript.RegisterStartupScript(Me.GetType(), "", "confirm(确认吗?);", True)
Dim m_txt As String = Me.txt.Text
Dim m_name As String = Me.lblName.Text
End Sub
End Class