Call Server Side Method without postback

Here i am to going explain little bit about how to call a Severside method without postbacking page, It is very simple learn and use. First we need to implement the ICallbackEventHandler interface to your code and also the two methods in that RaiseCallbackEvent and GetCallbackResult . Here is the sample code for that.

Partial Public Class WebForm3ClientCall

Inherits System.Web.UI.Page

Implements System.Web.UI.ICallbackEventHandler

Protected returnValue As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim cbReference As String = Page.ClientScript.GetCallbackEventReference(Me, "arg", "ReceiveServerData", "context")

Dim callbackScript As String = ""

callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}"

Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CallServer", callbackScript, True)

End Sub

Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements ICallbackEventHandler.RaiseCallbackEvent

If Not IsNumeric(eventArgument) Then

‘Call Buisness layer to get the Details here is sample demo code only you need your own logic to get some datas

Dim ObjPer As New Personal

returnValue=ObjPer.GetMydetailByID(eventArgument)

End If

End Sub

Public Function GetCallbackResult() As String Implements ICallbackEventHandler.GetCallbackResult

Return returnValue;

End Function

End End Class

And in Aspx code :

<asp:TextBox ID="txtwebin" runat="server" Width="200px"

MaxLength="100></asp:TextBox>

<img src="Get.gif" height="24px" width="25px" alt="Get Address" onclick=”GetMyAddress()” />

<script type="text/javascript">

function ReceiveServerData(rValue)

{

Alert("Your Address is "+rValue);

}

function GetMyAddress ()

{

Var myname= document.getElementById ('<%= txtwebin.ClientID %>').value;

CallServer(myname, "");

}

<script/>

Now, type the your name and click the image you will get javascript alert box says Your Address is 'some data'