Toars I will smile to the world ^o^

14Aug/090

Disable the history in the TextBox field / disable the AutoComplete for TextBox

When you want type in something in the TextBox field, It is very annoying that sometimes a long history is shown, besides, it is not secure at all, cause the others when using this computer that have the chance to see what you have typed in before.
Sure you want your application has such a drawback and annoys your application users? There are some ways to work around, you can either disable it using JavaScript, or disable it in the code-behind, or set the control property in the Aspx page.

If using JavaScript:

<script type="text/javascript">
    function disableTextBoxHistory(id){
        _obj = document.getElementById(id);
        if (_obj != null && _obj != undefined){
            _obj.setAttribute("autocomplete", "off");
            return true;
        }
        else
            return false;
    }
</script>



If in the code-behind:

TextBox1.Attributes.Add("autocomplete", "off");



In in the Aspx page:

<asp:TextBox ID="TextBox2" AutoCompleteType="Disabled"  runat="server" />



Why the history is shown? There are several reasons:

  • The AutoComplete Setting is turned on by default in some browsers,
  • The ID of the TextBox that shows the history is the same with the one in some pages before you have visited where you have typed in some texts.

What is the solution:
I don't have any good ways of solving it. Acutally, we can not touch the client side broswers to disable this AutoComplete setting. A not-so-smart way is to generate a random control id for the control on the fly.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.