Is it possible to implement ajax autocomplete control without using web service/web method? I mean i already have object with a method that gives me the values
public class Provider
{ public static string[] GetProviderNames()
{ // Get names frim cache if not there then
// connect to database, get the values, cache it for next use and return
}
}
When user type something in the textbox and hit enter i want some server side event to fire. How do i do that. remeber i dont have any button infront of TextBox. Also, when user hit enter i dont want any other control event to get fire. Only textbox change
event need to get fire.
There may be a better way, but javascript is not my strong point. The example below will fire an OnClick button event of an invisible button when the user presses ENTER (when the textbox has focus).
<asp:Button ID="button" runat="server" onclick="button_Click" style="display:none;" /> don't set visible=false (the button wont get rendered)
</script>Add to codebehind:
textbox.Attributes["onKeyDown"] = "javascript: if (TestForReturn()) document.all.button.click();";
If you're using a master page, do a view source to get the client button id and replace all.button.click with all.the client button id.click. Or in the code behind you can build the attribute string using button.ClientId.
Hope this helps... ~Rick
Please mark the post as ANSWER if it helps you
Disclaimer: Just my opinion. Not my employer or anyone else....
also how do i return result in TextBox based on what user selects. Suppose i have two radio buttons, and for each radio button i want certain kind of provider values how do i do that. Since
GetProviders(string prefixText,
int count) is static method i can not use radiobutton instance inside to check which one is selected.
guys i need help one more time..since the method GetCompletionList is static method, how do i use Sesion value inside static method.? The
GetCompletionList returns string array of "Program Names" but i want to return only those program names for certain country. and that country value is in Session..how do i do that?
Could you please explain me in clear how this is workin with out web service. I tried to create a method which gets the data from db and calling it as below
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
return GetAddress(prefixText);
}
but nothing is populated when I type in the text box.
lax4u
Participant
1592 Points
902 Posts
Autocomplete without web service..can we do that?
Feb 05, 2009 08:24 PM|LINK
Is it possible to implement ajax autocomplete control without using web service/web method? I mean i already have object with a method that gives me the values
public class Provider
{
public static string[] GetProviderNames()
{
// Get names frim cache if not there then
// connect to database, get the values, cache it for next use and return
}
}
How do i do that?
Rick Matthys
Contributor
2794 Points
406 Posts
Re: Autocomplete without web service..can we do that?
Feb 05, 2009 09:46 PM|LINK
This is about the best you can do....
Disclaimer: Just my opinion. Not my employer or anyone else....
chetan.sarod...
All-Star
65749 Points
11148 Posts
Re: Autocomplete without web service..can we do that?
Feb 06, 2009 02:14 AM|LINK
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
lax4u
Participant
1592 Points
902 Posts
Re: Autocomplete without web service..can we do that?
Feb 06, 2009 05:13 AM|LINK
cool works just fine...now one more question
When user type something in the textbox and hit enter i want some server side event to fire. How do i do that. remeber i dont have any button infront of TextBox. Also, when user hit enter i dont want any other control event to get fire. Only textbox change event need to get fire.
Rick Matthys
Contributor
2794 Points
406 Posts
Re: Autocomplete without web service..can we do that?
Feb 06, 2009 07:00 AM|LINK
There may be a better way, but javascript is not my strong point. The example below will fire an OnClick button event of an invisible button when the user presses ENTER (when the textbox has focus).
Add to aspx page:
<script type="text/javascript" language="javascript"> function TestForReturn() { if (event.keyCode == 13) { event.cancelBubble = true; event.returnValue = false; return true; } return false; }If you're using a master page, do a view source to get the client button id and replace all.button.click with all.the client button id.click. Or in the code behind you can build the attribute string using button.ClientId.
Hope this helps... ~Rick
Disclaimer: Just my opinion. Not my employer or anyone else....
lax4u
Participant
1592 Points
902 Posts
Re: Autocomplete without web service..can we do that?
Feb 06, 2009 04:00 PM|LINK
also how do i return result in TextBox based on what user selects. Suppose i have two radio buttons, and for each radio button i want certain kind of provider values how do i do that. Since GetProviders(string prefixText, int count) is static method i can not use radiobutton instance inside to check which one is selected.
lax4u
Participant
1592 Points
902 Posts
Re: Autocomplete without web service..can we do that?
Mar 13, 2009 03:26 AM|LINK
guys i need help one more time..since the method GetCompletionList is static method, how do i use Sesion value inside static method.? The GetCompletionList returns string array of "Program Names" but i want to return only those program names for certain country. and that country value is in Session..how do i do that?
lax4u
Participant
1592 Points
902 Posts
Re: Autocomplete without web service..can we do that?
Mar 13, 2009 03:38 AM|LINK
actually i got it...i can access session inside static method as HttpContext.Current.Session
swapna.anu
Contributor
2658 Points
745 Posts
Re: Autocomplete without web service..can we do that?
Jan 28, 2011 10:23 AM|LINK
Hi Rick,
Could you please explain me in clear how this is workin with out web service. I tried to create a method which gets the data from db and calling it as below
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
return GetAddress(prefixText);
}
but nothing is populated when I type in the text box.
Please help me with this.
Thanks in advance.
prakashgempa...
Member
2 Points
1 Post
Re: Autocomplete without web service..can we do that?
Feb 18, 2012 02:31 PM|LINK
[ScriptMethod] is for Ajax request to "GET" not for "POST"
[WebMethod]
Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the XML Web service.
see:
http://msdn.microsoft.com/en-us/library/byxd99hx%28v=vs.71%29.aspx
If you put break point and testing, remove and test it will work. In AjaxAutoCompleteExtender servicepath is not required if method in code behind.
-PrakashGempala