The manual test AutoCompleteWithContext in the ToolkitTests folder does this:
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
You should see the user specific context at the end of the completion list...<br />
User specific context: <asp:TextBox ID="UserContext" runat="server" /><br />
AutoComplete: <asp:TextBox ID="Address" runat="server" />
<ajaxToolkit:AutoCompleteExtender ID="AutoComplete" BehaviorID="AutoCompleteBehavior" runat="server"
TargetControlID="Address" ServiceMethod="GetCompletionList" />
<ajaxToolkit:AnimationExtender runat="server" TargetControlID="Address" />
<script type="text/javascript">
// Hook up to the AutoComplete populating/populated events
function pageLoad() {
var autoComplete = $find('AutoCompleteBehavior');
if (!autoComplete) return;
var target = autoComplete.get_element();
if (!target) return;
var userContext = $get('UserContext');
if (!userContext) return;
// Dynamically assign the context and change the color when processing
autoComplete.add_populating(function()
{
autoComplete.set_contextKey(userContext.value);
AjaxControlToolkit.Animation.ColorAnimation.play(target, 1, 20, 'style', 'backgroundColor', '#FFFFFF', '#EFC4C1');
});
autoComplete.add_populated(function()
{
AjaxControlToolkit.Animation.ColorAnimation.play(target, 1, 20, 'style', 'backgroundColor', '#EFC4C1', '#FFFFFF');
});
}
Kirti Deshpande
Program Manager, Silverlight and ASP.NET AJAX
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
Marked as answer by kirtid on Jun 09, 2007 09:05 PM
hey i was trying to pass additional value to autocomplete.cs other than prefixtext and count,is there any way to do that .iam trying to use autocomplete text box here
Hi all, here's a simple method I use for intranet websites that only require IE (works on IE7) and I have not tested with anything else.
Basically I dynamically add a "onchange" event to the textbox, and that works a treat for me.
private void initData(Guid horseID)
{
// The magic is all in this one line below, $find( ... use the behaviorID you specified above here not the server control id)
txtMake.Attributes.Add("onchange",
"$find('ModelExtender').set_contextKey(this.value);");
Hope this helps,
sorry guys for the font being so large ( I use consola's font pack in Visual studio and set the font size = 12pt which might screw up this forum post. )
Would be keen to hear from anyone if this works with other browsers.
Alan is a Microsoft dot net contractor and lives and works in Cambridge UK. He is also a part time software inventor and director of Goblinfactory where he works with and invests in internet startup businesses.
neils_77
Member
2 Points
3 Posts
Adding Textbox-Value to ContextKey of Autocomplete control
Jun 08, 2007 09:24 AM|LINK
Hi,
I'm using the contextKey parameter of the autocomplete-control to pass additional parameters to the webservice.
When i hardcode the contextkey-parameter like contextKey="testvalue" then it works. But how can a pass the textvalue
of a textbox to the contextKey parameter?
Any thoughts?
autocomplete contextKey
kirtid
Contributor
2610 Points
658 Posts
Microsoft
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Jun 09, 2007 01:12 AM|LINK
The manual test AutoCompleteWithContext in the ToolkitTests folder does this:
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /> You should see the user specific context at the end of the completion list...<br /> User specific context: <asp:TextBox ID="UserContext" runat="server" /><br /> AutoComplete: <asp:TextBox ID="Address" runat="server" /> <ajaxToolkit:AutoCompleteExtender ID="AutoComplete" BehaviorID="AutoCompleteBehavior" runat="server" TargetControlID="Address" ServiceMethod="GetCompletionList" /> <ajaxToolkit:AnimationExtender runat="server" TargetControlID="Address" /> <script type="text/javascript"> // Hook up to the AutoComplete populating/populated events function pageLoad() { var autoComplete = $find('AutoCompleteBehavior'); if (!autoComplete) return; var target = autoComplete.get_element(); if (!target) return; var userContext = $get('UserContext'); if (!userContext) return; // Dynamically assign the context and change the color when processing autoComplete.add_populating(function() { autoComplete.set_contextKey(userContext.value); AjaxControlToolkit.Animation.ColorAnimation.play(target, 1, 20, 'style', 'backgroundColor', '#FFFFFF', '#EFC4C1'); }); autoComplete.add_populated(function() { AjaxControlToolkit.Animation.ColorAnimation.play(target, 1, 20, 'style', 'backgroundColor', '#EFC4C1', '#FFFFFF'); }); }Program Manager, Silverlight and ASP.NET AJAX
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
neils_77
Member
2 Points
3 Posts
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Jun 09, 2007 02:28 PM|LINK
Hi,
yes, that was what I'm searching for. Thank you very much :)
vinavolu
Member
2 Points
1 Post
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Jul 11, 2007 10:52 PM|LINK
hey i was trying to pass additional value to autocomplete.cs other than prefixtext and count,is there any way to do that .iam trying to use autocomplete text box here
Thanks
MikeWasouski
Member
39 Points
9 Posts
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Oct 01, 2007 11:51 PM|LINK
Is so easy here is my code to do that, the textboxes where in of a formview, that "complicate" the code but is more functional [;)]
Cliente:<asp:TextBox ID="ADVIDTextBox" runat="server" OnTextChanged="ADVID_Changed" Text='<%# Bind("ADVID") %>' Width="70" autocomplete="off" AutoPostBack="true" />
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender_ADVID" runat="server" TargetControlID="ADVIDTextBox" CompletionInterval="250" MinimumPrefixLength="1" FirstRowSelected ="true" ServicePath="Webservices/ADVID.asmx" ServiceMethod="GetListaValores" CompletionSetCount="15" />
Cuenta:<asp:TextBox ID="ACCTIDTextBox" runat="server" Text='<%# Bind("ACCTID") %>' Autocomplete="off" Width="70" />
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender_ACCTID" runat="server" TargetControlID="ACCTIDTextBox" CompletionInterval="250" MinimumPrefixLength="1" FirstRowSelected ="true" ServicePath="Webservices/ACCTID.asmx" ServiceMethod="GetListaValores" CompletionSetCount="15" UseContextKey="true"/>
all the magic is here:
protected void ADVID_Changed(object sender, EventArgs e)
{
//AjaxControlToolkit.AutoCompleteExtender filtro = new AjaxControlToolkit.AutoCompleteExtender();
AjaxControlToolkit.AutoCompleteExtender filtro = (AjaxControlToolkit.AutoCompleteExtender)this.FV_HDR.FindControl("AutoCompleteExtender_ACCTID");
TextBox t1 = (TextBox)this.FV_HDR.FindControl("ADVIDTextBox");
filtro.ContextKey = t1.Text;
}
Mike Wasouwski
pianocompose...
Member
6 Points
6 Posts
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Oct 12, 2007 09:48 PM|LINK
This looks like a great solution but both FirstRowSelected and UseContextKey are not recognized as valid.
It says: <item> is not a valid attribute of element AutoCompleteExtender. The build failed.
I have AJAX 1.0. Hmm. Sure would love to know how you made the compiler take those attributes.
goblinfactor...
Member
2 Points
1 Post
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Feb 05, 2008 09:31 AM|LINK
Hi all, here's a simple method I use for intranet websites that only require IE (works on IE7) and I have not tested with anything else.
Basically I dynamically add a "onchange" event to the textbox, and that works a treat for me.
- - - aspx - - - -
<
asp:TextBox runat="server" ID="txtMake"/> <asp:TextBox runat="server" ID="txtModel"/><div id="lkpMake"></div>
<div id="lkpModel"></div>
<
ajax:AutoCompleteExtender ID="txtMake_AutoCompleteExtender" runat="server" MinimumPrefixLength="1"BehaviorID="makeExtender"
EnableCaching="false"
ContextKey="ck1"
DelimiterCharacters=";, "
CompletionListElementID="lkpMake"
ServiceMethod="GetMakes" TargetControlID="txtMake"></ajax:AutoCompleteExtender>
<ajax:AutoCompleteExtender ID="txtModel_AutoCompleteExtender" runat="server" MinimumPrefixLength="1"
BehaviorID="modelExtender"
EnableCaching="false"
ContextKey="ck1"
DelimiterCharacters=";, "
CompletionListElementID="lkpMake"
ServiceMethod="GetMakes" TargetControlID="txtMake"></ajax:AutoCompleteExtender> - - - - code behind - - - -
private void initData(Guid horseID)
{
// The magic is all in this one line below, $find( ... use the behaviorID you specified above here not the server control id)
txtMake.Attributes.Add("onchange", "$find('ModelExtender').set_contextKey(this.value);");
Hope this helps,
sorry guys for the font being so large ( I use consola's font pack in Visual studio and set the font size = 12pt which might screw up this forum post. )
Would be keen to hear from anyone if this works with other browsers.
Cheers,
Alan
autocomplete ajax extender toolkit autocompleteextender
erikkl2000
Member
257 Points
234 Posts
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Feb 16, 2008 04:26 PM|LINK
Thank you for this !
Solved my problem..
dzisaacs
Member
8 Points
19 Posts
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Feb 25, 2008 09:53 PM|LINK
what is FV_HDR
WzBn
Member
3 Points
9 Posts
Re: Adding Textbox-Value to ContextKey of Autocomplete control
Dec 04, 2008 10:52 AM|LINK
Thanks you very Match