IS there an event that fires when you select a text from an autocomplete extender? i am also getting the values from a database and is there a way to get the a corresponding value into another control(like into an hidden field, that would be really helpful).
Thank you
Hi ,
Please refer to this thread
autocomplete key value pair
Hope this helps
Hi Doulcat,
Here is the example
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TBSearch" runat="server"></asp:TextBox>
<asp:Panel runat="server" ID="myPanel" Height="100px" ScrollBars="Vertical">
</asp:Panel>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1"BehaviorID="myACEBID"TargetControlID="TBSearch"
ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="1"
CompletionInterval="1" EnableCaching="true" CompletionSetCount="12" CompletionListElementID="myPanel" />
<script type="text/javascript" language="javascript">
function pageLoad(){
$find("myACEBID").add_itemSelected(onItemSelected);
}
function onItemSelected(){
//add your javascript here
}
</script>
</form>
Hope this help.
Best regards,
Jonathan
Thank you for your help, it is helpful and i guess close to working(i am getting some results, but it is generating another error.)
I guess i will start another post for the new error. Thank you
What's your error Doulcat? I think that we're working on the same problem.
Also, can you please provide the javascript to pass the entered value of the textbox to a control parameter?
Sure the error i was getting was an exception: httprequest unhandled, and the inner exception was An extender can not be register before being prerender. All i had to do was called base.onprerender(e) where the page onprerender was overriden.
Sure for the javascript: i used<scriptlanguage="javascript"type="text/javascript">
function IAmSelected( source, eventArgs ) {
alert("KEY: "+eventArgs.get_text());
window.location = "www.somesite.com/page="+eventArgs.get_value();}
this is my extender<cc1:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"CompletionInterval="500"
CompletionSetCount="5"MinimumPrefixLength="1"ServiceMethod="GetCompletionList"
TargetControlID="TextBox1"UseKeyValuePairs="True"OnClientItemSelected="IAmSelected"></cc1:AutoCompleteExtender>
hope it helps. if not let me know, i have been struggling so much with it maybe i can.
I couldnt get it to work. i think that it has to do with my web service. It looks like you followed the earlier posts. I used the other guys suggestion and it seems to be working up until now. Can you please show me your web service? I need to see where to insert that first line. See right now I just need to pass the text box value to a control parameter to populate a dataview. I am trying to get away from the AutoPostBack in the textbox because it kills the web service after that.
Thanx
Cesar
I actually didn't use the web service, i couldn't get it to work(for some reason, the only difference with c# was that it wasn't static) But i did use the method in the page behind, here you go:
<Services.WebMethod()> _
<Script.Services.ScriptMethod()> _
PublicFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()Dim sqlAsString ="Your select string + where x=@.prefixText"
Dim daAs System.Data.SqlClient.SqlDataAdapter =New System.Data.SqlClient.SqlDataAdapter(sql,"Your connection string")da.SelectCommand.Parameters.Add("@.prefixText", System.Data.SqlDbType.VarChar, 50).Value ="%" + prefixText +"%"
Dim dtAs System.Data.DataTable =New System.Data.DataTable()da.Fill(dt)
Dim itemsAs Collections.Generic.List(OfString) =New Collections.Generic.List(OfString)(dt.Rows.Count)Dim drAs System.Data.DataRowForEach drIn dt.Rows
items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateKeyValuePair(dr("text").ToString, dr("value").ToString))Next
Return items.ToArray()
EndFunction
Text and value should be the name of the columns you get from the select string. the javascrip should be placed in the markup. I think the way to access a control is something like:
<scriptlanguage="javascript"type="text/javascript">
function IAmSelected( source, eventArgs ) {alert(" Key : "+ eventArgs.get_text());
alert ("Clearing message field");document.forms[0].elements["TextBox1"].value ='eventArgs.get_text()';
}
</script>
Hmmm...no luck. I'll keep at it.
Hi Doulcat,
Have you opened another post yet? Please provide as more as possible information in the new tread. We will discuss it on your new tread. Thanks
Best regards,
Jonathan
Hi Jonathan
i did open a new tread:http://forums.asp.net/t/1164269.aspx
Thanks for everything, i actually have it working. Now i am looking to improve on the displaying of the control. Any suggestions would be greatly appreciated. Thanks
No comments:
Post a Comment