Sunday, May 31, 2009

ASP.NET – Concept of Auto-Complete in Asp.Net

Introduction
This article will tell you about the concept of Auto-complete in ASP.NET.

What is Auto-Complete?
Auto-complete is a good and useful feature of popular browsers like Firefox and IE. You’ve seen this many times. You go to an online form and as you start to type in fields you get a drop-down showing values you’ve typed in that field before.Let’s take the simple and daily use example which I think every programmer will aware of, GOOGLE this is the name every person knows the internet will definitely know. Now here we’ll see the Auto-Complete using the google website. Whenever we type something in the google search box and click search it will display you the results related to that topic, now when again u type the same value it will display that word in the dropdown list below the search textbox automatically. See the following picture which will tell you this more clearly.Here in the below picture I am searching for “techAhead” (my blog), first time there is no dropdown list, when I click the search button it will display you the result related to techAhead. Here is nothing related to Auto-Complete topic but this is the origin of the concept, let’s move to the next picture and see the concept.



Now after seeing the results I closed my browser or clicks the back button or by any means I typed the techAhead again in the search box of google see the below picture which will displays a dropdown list this is the actual concept of Auto-Complete.



As you can see in the above picture that as I typed the “te” then it displays all the keyword or words that I have searched in the google’s search box earlier, So this is the actual Auto-Complete concept, this is not the case with only google’s search box it will be by default in all textboxes displayed on the websites until the Auto-Complete feature is not disabled for that textbox or it will not be enabled if it is a password textbox.

So “The Auto-Complete means a functionality provided by browsers which will automatically fills your textbox fields with the values that you have typed earlier in that same textbox, whenever you start typing with the same values in that textbox that you have entered earlier.”

Is Auto-Complete Useful?
In my point-of view its fifty-fifty (60%(YES) – 40%(NO)). That is 60% out of 100% it’s a useful feature but rest 40% this feature can create problems for you. How?

Advantages - Ok let’s take the positive (+ve) part first why it is useful. It is useful feature because it saves your time by filling your earlier values in the textbox automatically as you starts typing, whenever you starts typing the values it will display you the matches according to that values in the dropdown list, if you find that you need to type the value that is displayed in the dropdown then just select that value from either mouse or by arrow keys and click or press enter key, that value will be automatically filled in the textbox.
This feature is especially useful in case of Searching sites like google, at least I think this, because suppose you type something an searched in the google, then you got your result worked according to that finished your work and closed your system, then after sometime you think that you need the same result again but you don’t remember what you searched in the google then no worries because Auto-Complete is there for your help, just double click using mouse or just press the down-arrow keys twice in the textbox it will display you all the words that you searched for in the google. Same as google this feature is useful when you are filling some big and lengthy form again & again on website’s.

Disadvantages - Now we have discussed the advantage part of Auto-Complete but lets take a look of disadvantages.
This features help us lot but sometimes, it can harm you if it will not handled properly, Lets suppose someone has developed a site which takes your credit card details for transaction, and also you have no issue in giving the details to that website because it’s a SSL secured website, But In case they forget to disable the auto-complete feature for the credit card number textbox then What, that means if your in the cyber café and you entered you credit card details, you closed the website and gone, after sometime another person sits on that computer and opens the same website then it may the case that he’ll be able to find out your credit card details using this Auto-Complete feature and can misuse your details. OR you typed your email address somewhere in the site and someone if able to know that using this feature can misuse your email address, so this type of risks contains the 40% risk factor about the Auto-complete.

Solution to cure the risk for Auto-Complete
As a programmer if you asked then the simple solution is that where you think that it’s a risk are someone can misuse the user’s information if he find out those using this feature then disable the auto-complete feature for that textbox. I’ll explain it that how to disable this later in this article.
But if you are a normal user then the best and easy way to take prevention from your side is clear the auto-complete data, it can be done by clearing you browsers history, but sometimes the value of auto-complete not gone by clearing the history, so the best and easy way is Double click on the textbox, the dropdown menu containing the values will be displayed if having the values, then move one by one value and delete it by using the Del key in the keyboard. It will permanently clear the values.

How to disable Auto-Complete programmatically
This feature is enabled by default in all browsers, the big deal is to disable this feature properly in all browsers lets look at this, I am a asp.net developer so first i am discussing about the asp.net that how to disable or enable this feature in asp.net, in asp.net textboxes having an attribute (property) that is “AutoCompleteType” when you type this property and the it will display all the types for which you can make enable this feature there are many that’s why I am not discussing all those, Now to disable this you having the values Disabled and None. See the below pictures you’ll understand.








Now you think that you have disabled this auto-complete and it will not work for that particular textbox now, But this is not true, I don’t know why but these None and Disabled only works with IE in Firefox it will not disable the auto-complete feature and it will display that auto-complete dropdown.
So how to disable this for all browsers, the above property and case will only work for asp.net.
But the below code will work for all the browsers and in all the language like in ASP.NET, PHP, HTML with all browsers IE, Firefox etc. The below code uses a property called “Autocomplete” and value for this is “off”.



the above code will disable this feature in all browsers, in asp.net it will display a green line below this property but its not a big deal it will not create any problem for you. It will work. Actually this Autocomplete is the attribute of HTML input field but as you know that asp:textboxes are rendered as HTML input boxes when in the running on the browser so it will work perfectly for asp textboxes.

So here is all about this Auto-Complete concept, may be I left something important related to this concept, if anyone knows such thing then please let me know I’ll include it in my article.
Thanks,

4 comments:

Mohamed Ameen said...

These interview questions are very useful for all developers for their quick reference aprt from attending interview.
Well done Ashar! keep it up!!

Ameen said...

These interview questions are very useful for all developers for their quick reference aprt from attending interview.
Well done Ashar! keep it up!!

Regards,
Mohamed Ameen,
Software Engineer,
Emirates Airline,
Dubai,
UAE.

Shiham : said...

Very Useful machan!

Keep it up

nintendo ds r4 said...

Nice post. This seems to be self written. Im glad I came to this blog.