Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do a client callback using vbscript? 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I'm using ASP.Net 2.0 and am trying to figure out how to perform client callbacks. I've seen complicated examples using javascript but none using vbscript. Does anyone know how to do it in vbscript?

For an example, I would like to call a server-side class function from a html page. All the server-side class function needs to do is to return the current system time and date as a string.

Any help?
 
You cannot, strictly speaking.

You can use AJAX to generate a second, "hidden" request via the XMLHTTPRequest object. Sorry, I don't have a VBScript example.

The web doesn't support "client callbacks", only HTTP Get and Post, period.







Thomas D. Greer
 
Are you saying it can't be done with vbscript or it can't be done period?
 
I'm doing callbacks with 2.0 but with Javascript...seems that you'd just need to format your script correctly...let me know if you want me to post my code...as I struggled with examples that I found on the web as well..

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
checkai.. I would like to see your code since the examples I have found are complicated.

Thanks,

Jim
 
checkai, I would appreciate a simple example of how it works (like the example I explained in my first post). I'm sure you're busy and understand if you can't get to it.
 
here's my javascript code
Code:
<script language="javascript" type="text/javascript">   
function ClientCallback(result, context){
 var DropDown = document.forms[0].elements['<%=listbox.UniqueID%>'];

 if (!DropDown){
  return;
 }

 DropDown.length = 0;
 if (!result){
  return;
 }
      
 var rows = result.split('|'); 
 for (var i = 0; i < rows.length; ++i){
  var shz = rows[i].split('^');
  var option = document.createElement("OPTION");
  option.value = shz[0];
  option.innerHTML = shz[1];
  DropDown.appendChild(option);
 }
 DropDown.selectedIndex=0;
}

function ClientCallbackError(result, context){
 alert(result);
}
</script>

<asp:TextBox ID="txtSearch" runat="server" onkeyup="Search(this.value + '%', 'ddl');" EnableViewState="False"> </asp:TextBox>

vb code
Code:
Partial Class wfrmHome
 Inherits System.Web.UI.Page
 Implements ICallbackEventHandler
 Private callbackresult As String

 Private Sub Page_Load(ByVal source As Object, ByVal e As System.EventArgs)
  Dim callBack As String = Page.ClientScript.GetCallbackEventReference(Me, "arg", "ClientCallback", "context", "ClientCallbackError", False)
  Dim clientFunction As String = "function Search(arg, context){ " & callBack & "; }"
  Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "Search", clientFunction, True)
 End Sub

 Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
  Return callbackresult
 End Function

 Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
  Dim a As MyData = New MyData
  Dim dt As Data.DataTable = a.searchClient(eventArgument, "dc9974")

  If dt.Rows.Count > 50 Then
    callbackresult = "0^...searching..."
  ElseIf dt.Rows.Count = 0 Then
    callbackresult = "0^...no clients found..."
  Else
    Dim str As String = ""
    Dim i As Integer = 0
    Do While i < dt.Rows.Count
     str += dt.Rows(i)("clientID") & "^" & dt.Rows(i)("clientName") & "|"
     i += 1
    Loop
    callbackresult = str.Remove(str.LastIndexOf("|"), 1)
  End If

  dt.Dispose()
  dt = Nothing
  a.Dispose()
  a = Nothing
End Sub

  Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelect.Click
    Dim cID As Integer = CInt(Request.Form("listbox"))
  End Sub
End Class

this code basically does a client search as you type in the text box...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Ok, I'm stupid. I can't get the example to run (note this is my first asp.net app...so what do I need to do to make it work?
 
you'll need to change a few things...for instance this code is calling a search class that i have...

Code:
Dim a As MyData = New MyData
Dim dt As Data.DataTable = a.searchClient(eventArgument, "dc9974")

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
But you can see from that code that a true "callback" isn't being done. The textbox is coded to run on the server, and the server code runs each time a key is released. You can call it a "callback" if you wish, but it's really just an HTTP Post.

Nevermind, it's just semantics I suppose.

Thomas D. Greer
 
Semantics that I don't understand!! but I believe Asp.Net 2 advertises it as "Client Callback" don't they?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
There is a MSDN article on client callbacks with an example walkthrough if anyone is having problems understanding them:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
checkai, I think the reason I couldn't get your example to work is because I have the beta version of 2.0. It's missing some things.

ca8msm, the link looks promising. I will check it out after the New Year.
 
Hmm. I see the teriminology, yes, but the only way for a page to send a "request" to a server is via HTTP Get/Post or the XmlHttpRequest object. To keep the page "live in the client browser" while sending and a processing a separate request is known in the web development community as "AJAX".

It appears ASP.NET exploits this but is calling it "Client Callbacks" instead. All well and good, I suppose.



Thomas D. Greer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top