Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » Ajax » Controls » Downloads
 
Add your own
alternative version

An Easy Way to Implement ASP.NET Callback

, 3 Sep 2010 CPOL
Implementing callback inside User Control, choosing between client callback and Ajax framework
CallBackHandler.zip
CallBackHandler
App_Data
CallbackHandler-TestProject
TestProject1
bin
Debug
TestProject1.dll
WebTest1.webtest
WebTest2.webtest
My Project
TestProject1.suo
WebTest1.webtest
WebTest2.webtest

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub CallBackHandler1_RaiseCustomCallback(ByVal eventArgs() As String, ByVal HandlerNumber As Integer, ByRef CallBackResult As String, ByRef ExcutableClientScript As String, ByVal RaiseException As System.Exception) Handles CallBackHandler1.RaiseCustomCallback
        '
        '
        ' let speak about parameters of this sub
        '
        '   eventArgs() : 
        '                   an array of parameters which passed from cliet side
        '   
        '   HandlerNumber :
        '                  if callback fuction on a particular page be used more than once,each one should be distinctive using HandlerNumber Parameter
        '                  so when this Sub triggered u can Distinguish which client side function has fired 
        '
        '   
        '   CallBackResult :
        '
        '                   Anything u want to show on page should be set to this parameter.
        '                   the content of this parameter will be pushed on page without postback. content can be pure text or html text
        '
        '
        '
        '   ExcutableClientScript :
        '                   Any scripts u want to excute on page should be set to this parameter.
        '
        '
        '   RaiseException :
        '                   exception 


        Dim param1 As String, param2 As String, param3 As String

        Select Case HandlerNumber

            Case 1 ' sample 1

                If RaiseException Is Nothing Then

                    param1 = eventArgs(0)
                    param2 = eventArgs(1)
                    param3 = eventArgs(2)

                    Dim sb As New StringBuilder
                    sb.AppendFormat("the form was submitted at {0}", Now.ToShortTimeString())
                    sb.Append("<br/>")
                    sb.AppendFormat("param 1 vales : {0}", param1)
                    sb.Append("<br/>")
                    sb.AppendFormat("param 2 vales : {0}", param2)
                    sb.Append("<br/>")
                    sb.AppendFormat("param 3 vales : {0}", param3)

                   
                    Dim excutableScript As New StringBuilder
                    excutableScript.Append("document.getElementById('txtParam1').value = '';")
                    excutableScript.Append("document.getElementById('txtParam2').value = '';")
                    excutableScript.Append("document.getElementById('txtParam3').value = '';")
                    excutableScript.Append("alert('thank u for submiting form.');")


                    '------------------  filling parameter ----------

                    ExcutableClientScript = excutableScript.ToString()

                    CallBackResult = sb.ToString()
                    '------------------------------------------------

                End If

            Case 2 ' sample 2

                If RaiseException Is Nothing Then

                    param1 = eventArgs(0)
                    param2 = eventArgs(1)

                    Dim sb As New StringBuilder
                    
                    sb.AppendFormat("param 1 : {0}", param1)
                    sb.Append("<br/>")
                    sb.AppendFormat("param 2 : {0}", param2)
                  
                    Dim excutableScript As New StringBuilder
                    excutableScript.Append("document.getElementById('txtParam1_Sample2').value = '';")
                    excutableScript.Append("document.getElementById('txtParam2_Sample2').value = '';")
                    excutableScript.Append("alert('thank u for submiting form.');")


                    '------------------  filling parameter ----------

                    ExcutableClientScript = excutableScript.ToString()

                    CallBackResult = sb.ToString()
                    '------------------------------------------------

                End If

        End Select

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mohammad A Gharakhanlou
Software Developer asemantek.ir
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 3 Sep 2010
Article Copyright 2010 by Mohammad A Gharakhanlou
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid