English 中文(简体)
Stop browser from filling textboxes with details
原标题:

I ve run into a really annoying problem, and I m hoping it s just a setting I ve missed. I ve got an ASP.NET application which allows users to enter their username/password in various places (e.g. login, change password, change username etc..). When I logged in, the browser asked if I would like to store the user details. Usually, I click no , but this time I decided to click yes . Now, certain textboxes in my form are prefilled with the username or password. Is it possible to remove these, as they sometimes appear in textboxes which shouldn t be prefilled. I tried setting AutoCompleteType=none and Text= but it still gets prefilled. The textboxes don t have much in common, except the same CssClass and, for password boxes, TextMode=password. The names are different, although sometimes they include the word name (e.g. fullName, userName). Is there a way to stop the browser from filling certain textboxes?

Thanks

最佳回答
  <input type="text" name="Username" autocomplete="off">

You can also put this on the form tag. Note this does not work consistently in all browsers.

问题回答

The only solution that worked for me was to include two fields, one for login and one for the password with display: none <input type="text" style="display: none"> <input type="password" style="display: none">

if you set autocomplete="off"... the textbox will loose every words on its history... but if you want to prevent browser saved usernames and password, the best way is to put these tags in top of your page:

<input type="text" style="display: none"> 
<input type="password" style="display: none">
<asp:TextBox ID="Text1" runat="server" AutoCompleteType="Disabled"></asp:TextBox>

If you happen to work in a much more updated framework, this code should work as expected. It has been 8 years ago and some of the answers here is outdated.

In my case I needed both: autocomplete="off" AutoCompleteType="Disabled"

I am also using time picker from rome.js and preventing user from typing into textbox on keydown which complicated things.

<asp:TextBox ID="txtReturnTime" autocomplete="off" AutoCompleteType="Disabled" onkeydown="this.blur();" AutoPostBack="true" runat="server" ClientIDMode="Static"></asp:TextBox>

<script>
rome(txtReturnTime, { date: false, min:  07:15 , max:  15:31 , timeInterval: 900 });
</script>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签