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!

Callback Basics

Status
Not open for further replies.

checkai

Programmer
Jan 17, 2003
1,629
US
First off, I'd like a run through of how/what happens during this callback code...i've modified it slightly..right now it searches a db and parses out the results to a listbox...ultimately, what i'd like is, when the user has typed in the 3rd character then the search will start...also, if there is a way to bind the listbox with something other than a parsed pipe delimited string...

.aspx
Code:
<script language="javascript" type="text/javascript">

   function ClientCallback(result, context){
      alert('here');
      var childDropDown = document.forms[0].elements['<%=ListBox1.UniqueID%>'];

      if (!childDropDown){
         return;
      }

      childDropDown.length = 0;

      if (!result){
          return;
      }
      
      var rows = result.split('|'); 
      for (var i = 0; i < rows.length; ++i){
         var option = document.createElement("OPTION");
         option.value = rows[i];
         option.innerHTML = rows[i];     
         childDropDown.appendChild(option);
      }
      
      childDropDown.style.visibility = "visible";
   }

   function ClientCallbackError(result, context){
      alert(result);
   }

   </script>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>&nbsp;<br />
  <br />
  <br />
  <asp:TextBox ID="TextBox1" runat="server" onkeyup="GetChildren(this.value + '%', 'ddl');"></asp:TextBox><br />
  <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>

.vb
Code:
Partial Class CallBackEventHandler_vb
  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 GetChildren(arg, context){ " & callBack & "; }"
    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "GetChildren", clientFunction, True)

    If Page.IsPostBack AndAlso Not Page.IsCallback Then

      Label1.Text = "You Selected: " & Request.Form("ParentDropDown") & ": " & Request.Form("ChildDropDown")
    End If

    If Page.IsCallback Then
      Label1.Text = "You Selected: " & Me.ListBox1.Items.Count
    End If
  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 str As String = 0
    Dim i As Integer = 0
    Do While i < a.searchClient(eventArgument, "dc0974").Rows.Count
      str += a.searchClient(eventArgument, "dc0974").Rows(i)("clientName") & "|"
      i += 1
    Loop
    callbackresult = str
  End Sub

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Response.Write(Me.ListBox1.Items(0).Text)
  End Sub
End Class

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
If you were working with ASP 2.0 with Atlas (free) this is very possible.

Check out. MSDN WEBCAST - Client Side callbacks in ASP 2.0 (and other things)

atlas is at...
atlas.asp.net

There are some very cool features of asp 2.0 including async callbacks that you can take advantage of with atlas..

only doing partial page loads..i.e post back one control and return just the contents of another (not the whole page)...

verry verrryyy coooollll

Rob


HTH


Rob
 
i've got this to work a little...however, it isn't working with a master page right now...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Is the masterpage is overriding your inheritence? do you need to have the masterpage inherit.. (it is strange though as I would have thought the master page just inserted tags around you content, but it might be the other way around...

(check out atlas though. you might find it solves problmes you didn't know you had :)

Rob
 
it has something to do with the way controls are named...i read somewhere to use the .clientID of the control instead of the .uniqueID when using a master page...but that didn't seem to do it...i'll take a look at atlas...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top