Truly I was looking for a way to use callback method to avoid page post back.
I found a good sample of calling server side methods using
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<
head
runat
=
"server"
>
<
title
>Untitled Page</
title
>
<
script
type
=
"text/javascript"
>
function GetID()
{
var valueID = document.getElementById("txtID").value;
DoServerAction(valueID,'');
}
function ReceiveDataFromServer(data)
{
document.getElementById("myNewData").innerHTML =data
}
</
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
input
id
=
"txtID"
type
=
"text"
/>
<
input
type
=
"button"
value
=
"Submit"
onclick
=
"GetID()"
/>
<
br
/>
<
div
runat
=
"server"
id
=
"myNewData"
></
div
>
</
form
>
</
body
>
</
html
>
Partial
Class
_Default
Inherits
System.Web.UI.Page
Implements
System.Web.UI.ICallbackEventHandler
Protected
ReturnData
As
String
=
""
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
Dim
CR_REF
As
String
= ClientScript.GetCallbackEventReference(
Me
,
"myValue"
,
"ReceiveDataFromServer"
,
"validateF"
)
If
Not
ClientScript.IsClientScriptBlockRegistered(
"DoServerAction"
)
Then
Dim
SERVER_SCRIPT
As
String
=
" function DoServerAction(myValue,validateF) { "
+ CR_REF +
"}"
ClientScript.RegisterClientScriptBlock(
Me
.
GetType
(),
"DoServerAction"
, SERVER_SCRIPT,
True
)
End
If
End
Sub
Public
Function
GetCallbackResult()
As
String
Implements
System.Web.UI.ICallbackEventHandler.GetCallbackResult
Dim
template
As
String
=
""
If
ReturnData.ToLower =
"name"
Then
template =
"Morteza K"
ElseIf
ReturnData.ToLower =
"address"
Then
template =
"Never land"
Else
template =
"Please Use Valid KeyWord--> Name , Address"
End
If
Return
template
End
Function
Public
Sub
RaiseCallbackEvent(
ByVal
eventArgument
As
String
)
Implements
System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
If
Not
String
.IsNullOrEmpty(eventArgument)
Then
ReturnData = eventArgument
End
If
End
Sub
End
Class