What is the best way to implement custom controls requiring AJAX callbacks?
I want to do a few things:
- Events executed in the browser (e.g. drag and drop) trigger an AJAX notification that can trigger a control event that triggers code on the page using the control to do whatever it needs (e.g. change the value to the database).
- Partially update (without using the update panel) that can do things such as populating the auto-download drop-down list under the text box.
- Implement a single user control that is versatile enough to be reused across multiple pages.
- Avoid the need to implement logic on the page itself, which passes events back to the control, because it repeats and is difficult to maintain
I use jQuery for most of the client side, but for real AJAX calls, I don't care if it's jQuery or ASP AJAX libraries.
Effectively, what would be ideal is PageMethods in a user control that could easily be called from the client side of the script. Unfortunately, as far as I know, pagemethods do not work with user controls.
As an example, I will use autocomplete:
I should be able to include an autocomplete element on the page, and then in the page code, for example:
Public Sub HandleLookup(ByVal input As String, ByRef list As List(Of String) Handles MyControl.LookupEntries
list = New List(Of String)
' Query database for list of items..
For Each item as String in FullItemList
If item.StartsWith(input) then list.Add(item)
Next
Return list
End Sub
And do nothing. The rest of the code should be in usercontrol.
. , , , , , . - , .