Hiren
Hiren

Reputation: 1391

Force Value To Text of TextBox

I have a TextBox and I have Datatable. I give TextBox Suggetions with Datatable. So when we enter key it gives suggetions for keys typed .Now what I want is user shoud not type key if it is not in datatable.

For Example I have datatable with keywords of abc,abd,abe,abe . So user can type 'ab' in textbox but not 'ac' because ac is not in datatable.Is it possible??

Upvotes: 0

Views: 293

Answers (2)

Seany84
Seany84

Reputation: 5596

You could use the AJAX control Toolkit's - Filtered Textbox: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/FilteredTextBox/FilteredTextBox.aspx

In the code-behind: you could read the data and specify the ValidChars property.

<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
    TargetControlID="TextBox3"         
    FilterType="Custom"
    ValidChars="ab" />

You could also use the AutoComplete extender to get the suggestions: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx

Upvotes: 3

ShaunOReilly
ShaunOReilly

Reputation: 2206

I assume this is asp.net with C# code behind.

Just return false on the keypress event, when you are not happy with the new character.

Returning false, will cancel the event.

Some more ideas can be found at: http://www.codeproject.com/KB/aspnet/AutoComplete.aspx

Upvotes: 1

Related Questions