|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionHighrise and other new AJAX enabled tools have this feature that when you type in a search query, it automatically updates the search results below. It's almost like an auto-complete box, but with the full results on the page instead of a dropdown list below the control. Unfortunately, I didn't find anything like this in the Microsoft ASP.NET AJAX Toolkit. So, I decided that this was a good way to finally dive into the AJAX Control Toolkit. Here is the result: Live Demo. It's my first AJAX control, so I'm sure there is room for improvements. I've tested it in IE7, FF, and Safari. Seems to work fine in all of them. BackgroundI used the Membership Editor Example from Peter Keller and TextChangedBehavior.js from Garbin as my inspiration and resource, but started with a VS ASP.NET AJAX Control Project to get the framework up and running. The Use CaseThe user starts typing his search query into the textbox. After he types in the first few characters of the keyword he is looking for, he pauses. Magically, all search results that fit his query so far appear below. If he types in more of the keyword, the results are updated accordingly. Example: A user is seaching for a contact. He types Bl and stops. The names that now show up could include:
Now, he types another letter, let's say, o, and the list reduces itself to:
The ControlThere is really only JavaScript code that has functionality. The only thing the code does is start a time on the _onkeyup : function(ev) {
var k = ev.keyCode ? ev.keyCode :
ev.rawEvent.keyCode;
if (k != Sys.UI.Key.Tab) {
this._timer.set_enabled(true);
}
},
_onkeydown : function(ev) {
this._timer.set_enabled(false);
},
_onTimerTick : function(sender, eventArgs) {
this._timer.set_enabled(false);
if(this._text != this.get_element().value) {
this._text = this.get_element().value;
this.get_element().onchange();
}
},
Everything else is just setup and teardown code. There is one property in the C# file called Using the CodeJust add this control like any other Extender to your ASPX page, set the <cc1:DelayedSubmitExtender
ID="DisableButtonExtender1"
runat="server"
Timeout="1000"
TargetControlID="TextBox1"/>
<asp:TextBox
ID="TextBox1"
runat="server"
AutoPostBack="True"
OnTextChanged="TextBox1_TextChanged"
Columns="50"></asp:TextBox>
<br />
List of matching words:<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TextBox1" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li><%#DataBinder.Eval(Container, "DataItem[0]")%></li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
I would then wrap the search results area in an Code-behindprotected void TextBox1_TextChanged(object sender, EventArgs e)
{
List<string[] /> items = new List<string[] />();
for (int i = 0; i < wordlist.Length; i++ )
{
if (wordlist[i].StartsWith(
TextBox1.Text,
StringComparison.OrdinalIgnoreCase))
{
string[] item = new string[1];
item[0] = wordlist[i];
items.Add(item);
}
}
Repeater1.DataSource = items;
Repeater1.DataBind();
}
In the I would recommend to just have a look at the example. It's very simple, and should show you how this works. Please let me know how it works and if it is of any use. Good luck!
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||