<script type="text/javascript"> function Success(args, context) { if (args != 'error') { alert('执行的是' + args + '方法'); if (args == 'Confirm') { document.getElementById('txt').value = 'aaa'; document.getElementById('txt1').value = 'name name'; document.getElementById('txt2').value = 'aaa'; //document.getElementById('lblName').innerHtml = 'abababab'; } else { document.getElementById('txt').value = ''; document.getElementById('txt1').value = ''; document.getElementById('txt2').value = ''; //document.getElementById('lblName').innerHtml = ''; } } } function Error(args, context) { alert('error'); docume.t.getElementById('lblName').value = ''; } </script>
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
asp.net 前后台交互 ICallbackEventHandler
最新推荐文章于 2014-10-19 19:18:00 发布