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
.vb
"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
.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> <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..."