ASP.NET文本框(HTML输入字段)填充与用户名的形式自动负载时 [英] ASP.NET TextBox (HTML input field) populates with username automatically when form loads

查看:411
本文介绍了ASP.NET文本框(HTML输入字段)填充与用户名的形式自动负载时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形式,仍然是在数据拉当HTML表单呈现一个TextBox控件。我尝试设置AutoCompleteType为无,但我认为只是控制它是否会找到previously输入的数据为这一领域,而不是实际进入填充在页面加载时的输入字段。为什么会这样文本框在数据拉?这是造成另一个更大的问题。这是文本框控件(* .ascx文件)内。它是从另一个动态控件加载 - 不知道如果该事项。这只是发生在Mozilla Firefox。当我在包含文本框控件的Page_Load事件检查txtKeywords.Text,该值为null。所以价值显然是从浏览器,而不是服务器来。什么会导致此?

 < ASP:文本框的id =txtKeywords=服务器WIDTH =125pxAutoCompleteType =无自动完成=FALSE>< / ASP:文本框&GT ;

渲染HTML:

 <输入类型=文本的风格=WIDTH:125px;自动完成=FALSEID =ExplorerPageHtmlLeft_ctl01_txtKeywordsNAME =$ ExplorerPageHtmlLeft $ ctl01 txtKeywordsgtbfieldid =77>

家长控制code的后面(searchPanel1控件包含文本框):

 私人小组的Page_Load(BYVAL发件人为对象,_
                          BYVALË作为EventArgs的)_
            处理MyBase.Load
        navigation1 = CTYPE(LoadControl(ExplorerNavigation1.ascx),ExplorerNavigation1)
        sea​​rchPanel1 = CTYPE(LoadControl(SearchPanel.ascx),SearchPanel)
        navigation2 = CTYPE(LoadControl(ExplorerNavigation2.ascx),ExplorerNavigation2)        Me.PlaceHolder1.Controls.Add(navigation1)
        Me.PlaceHolder1.Controls.Add(searchPanel1)
        Me.PlaceHolder1.Controls.Add(navigation2)
    结束小组

我无法找到任何可疑的JavaScript然而,的Massimiliano Peluso的的评论之后。但是,我也注意到,在此输入字段的值总是一样的用户的ID。在TxtUser领域的gtbfieldid属性的值似乎总是当我检查在Firebug的元素来改变。这TxtUser场是从我们txtKeywords输入字段总是不同的。他们在不同的页面。他们似乎每次都使用不同的值来填充。所以,我没有看到相关那里。我还是不知道这个属性是。此属性不会在Internet Explorer中显示,所以它必须被插入到Firefox出于某种原因。

 <输入类型=文本ID =TxtUserNAME =TxtUsergtbfieldid =37>

由于约翰尼#5的投入,我们证明了该服务器没有设置这个文本。这不是回答我的问题,但是这是非常有益的。我把一个断点到二传手,并没有被调用。只有吸气接到电话。为了澄清的事情,这是一个自定义Web服务器控件( .vb文件),不要与一个自定义用户控件(的.ascx文件,* .ascx.vb文件有时*的.ascx混淆。 Designer.vb文件)。我加渲染事件此类。我也不得不进口2的命名空间。 我想弄清楚接下来的事情是一种方法,能够扩展浏览器的设置文本在这一领域(通过客户端)的能力,就像我们下面的服务器端。这将是对这种类型的问题frickin'真棒方法论。不知道萤火虫有能力虽然。我仍然不知道发生了什么设置这个文本。所以我的问题仍然是待价而沽。

 进口的System.Web
进口System.Web.UI.WebControls公共类MyTextBox
    继承System.Web.UI.WebControls.TextBox    公共覆盖属性文本()作为字符串
        得到
            返回MyBase.Text
        到底得的
        设置(BYVAL值作为字符串)
            MyBase.Text =价值
        结束设定
    高端物业    受保护的覆盖分渲染(BYVAL作家作为System.Web.UI.HtmlTextWriter)
        MyBase.Render(作家)
    结束小组末级

在我的页面,在这里我实现这个自定义Web服务器控件,我需要注册这个类。

 <%@注册大会=Acu.LIMS.UI.Web命名空间=Acu.LIMS.UI.Web标签preFIX =MyTextBox%GT ;< MyTextBox:MyTextBox ID =txtKeywords=服务器WIDTH =125pxAutoCompleteType =无自动完成=FALSE>< / MyTextBox:MyTextBox>

好吧,我不是疯了!这不是服务器端code,它不是客户端code导致此。这是Mozilla Firefox浏览器的>选项>安全>记住密码复选框,造成问题的原因。但我仍然感到困惑。 : - \\

在导致该问题的电脑,我不停地切换此复选框,无法让浏览器来问我这个问题,你想的Firefox记住您的密码? (不记得确切的字眼)。但另一台计算机上,我被立刻问道。而当我点击记住,去到该页面中,x显示在此输入字段(又名TextBox Web控件)。我的两个用户名和密码均为×,所以我不知道它是拉动。尽管它拉的价值,我的罪魁祸首文本框没有任何标识,因为它的ID(用户ID或密码)。 下一步问题:如何火狐确定何时在用户名和密码填写关于这种形式的一个有趣的事情是,另一场确实有密码文本框,但我没有用户ID以这种形式? 。我不知道如果Firefox让用户名发现?第一场

=======================

所以我把在一个虚拟的字段中SearchPanel控制,并猜出我的用户名填写。我在阅读关于Mozilla的密码管理器这个环节上,显然Mozilla使用其情报,以确定把最好的地方用户ID(有时被称为用户名)。就我而言,我对我的身份验证控制用户名(不是用户ID),一个标签,但我不希望用户id字段。由于用户已经登录,他们不应该被输入任何用户ID。所以这就是为什么用户名标签是在密码字段的前面。我们在审核我们的应用程序的变化,所以这是宗旨,为具有应用程序里面。

https://wiki.mozilla.org/Firefox%3aPassword_Manager

所以,我做了一个测试,以验证Mozilla的功能。我把另一个空场旧的罪魁祸首文本字段(ID为txtKeywords之后,因此它的位置是最后一个输入字段preceding密码输入字段。猜猜哪里Mozilla Firefox浏览器将用户ID?是的,在虚拟文本框/输入字段。当我关闭了站点记住密码Mozilla的选项下>选项>安全,它不填充,也没有我的密码字段。这就是我的答案。现在我猜,我会只是把一个隐藏的文本框场在我的身份验证控制,Mozilla的填充一个代替,但不可见。

SearchPanel.ascx控制:

 < TR>
    < TD NOWRAP类=categoryverticalNav>
        < ASP:标签ID =lblSearch=服务器>搜索和LT; / ASP:标签>< BR>
        < ASP:DropDownList的ID =ddlCategory=服务器WIDTH =164px>< / ASP:DropDownList的>< BR>
        < ASP:文本框的id =txtKeywords=服务器WIDTH =125pxAutoCompleteType =无自动完成=FALSE>< / ASP:文本框>&安培; NBSP;
        < ASP:文本框的id =TextBox1的=服务器WIDTH =125pxAutoCompleteType =无自动完成=FALSE>< / ASP:文本框>&安培; NBSP;
        < ASP:按钮的ID =btnGo=服务器WIDTH =28px文本=加油的CausesValidation =FALSE/>
    < / TD>
< / TR>

是的,投入在一个隐藏的输入字段解决它。我想我可以要么把在TextBox还可以,但我只是选择了一个输入字段=服务器。自CLR并不需要在ASP.NET与它进行交互。一旦我这样做,在X(用户ID)从SearchPanel控制txtKeywords输入字段消失。 : - )

 < TD>
    < B>< ASP:标签ID =LblUserDisplayName=服务器的EnableViewState =假>< / ASP:标签>< / B>
< / TD>
< TD>密码和LT; / TD>
&所述; TD>
    <输入=服务器类型=文本的风格=显示:无;>
    < ASP:文本框的id =TxtPassword=服务器WIDTH =80的EnableViewState =假的TextMode =密码>< / ASP:文本框>
< / TD>


解决方案

看我为答题的底部。这一切都说明。从本质上讲Mozilla Firefox浏览器的密码管理器把用户ID进入最后输入字段preceding存储的输入字段(根据什么保存在Mozilla Firefox的密码管理器)。所以我只是要地方precedes我的密码输入字段我的验证控件中隐藏的文本框虚拟(或输入)字段。

这篇文章有一个报价之类的解释,但我想我有一个更好的解释。

https://wiki.mozilla.org/Firefox%3aPassword_Manager

从以上链接引用:

然后使用usernamefield / passwordfield值的提示,他们匹配的寻找网页中的适当元素name属性。

I have a TextBox control in a form which is still pulling in data when the HTML form renders. I tried setting the AutoCompleteType to "None" but I think that just controls whether or not it will find previously entered data for that field, not what actually fills into that input field when the page loads. Why would this textbox be pulling in data? It's causing another larger issue. This TextBox is inside of a control (*.ascx file). It's loaded from another control dynamically--not sure if that matters. It's only happening in Mozilla Firefox. When I check txtKeywords.Text in the Page_Load event of the control that contains the TextBox, the value is null. So the value is obviously coming from the browser, not the server. What would cause this??

<asp:TextBox id="txtKeywords" runat="server" Width="125px" AutoCompleteType="None" autocomplete="False"></asp:TextBox>

Rendered HTML:

<input type="text" style="width: 125px;" autocomplete="False" id="ExplorerPageHtmlLeft_ctl01_txtKeywords" name="ExplorerPageHtmlLeft$ctl01$txtKeywords" gtbfieldid="77">

Parent control code behind (searchPanel1 control contains the TextBox):

    Private Sub Page_Load(ByVal sender As Object, _
                          ByVal e As EventArgs) _
            Handles MyBase.Load
        navigation1 = CType(LoadControl("ExplorerNavigation1.ascx"), ExplorerNavigation1)
        searchPanel1 = CType(LoadControl("SearchPanel.ascx"), SearchPanel)
        navigation2 = CType(LoadControl("ExplorerNavigation2.ascx"), ExplorerNavigation2)

        Me.PlaceHolder1.Controls.Add(navigation1)
        Me.PlaceHolder1.Controls.Add(searchPanel1)
        Me.PlaceHolder1.Controls.Add(navigation2)
    End Sub

I couldn't find any suspicious JavaScript yet, after Massimiliano Peluso's comment. However, I did notice that the value in this input field is ALWAYS the same as the user's id. The value of the "gtbfieldid" attribute on the TxtUser field always seems to change when I inspect the element in Firebug. This TxtUser field is always different from our txtKeywords input field. They are on different pages. And they seem to populate with different values each time. So I didn't see a correlation there. I still don't know what this attribute is for. This attribute doesn't show in Internet Explorer, so it must be inserted into Firefox for some reason.

<input type="text" id="TxtUser" name="TxtUser" gtbfieldid="37">

Thanks to Johnny #5's input, we proved that the server was not setting this text. This is not the answer to my question, but this was very helpful. I put a breakpoint into the setter, and it did not get called. Only the getter got called. To clarify things, this is a custom web server control (.vb file), NOT TO BE CONFUSED with a custom user control (.ascx file, *.ascx.vb file and sometimes *.ascx.Designer.vb file). I added Render event to this class. I also had to import 2 namespaces. The next thing I'd like to figure out is a way to be able to extend the browser's ability to set text in this field (via client side), like we did below for the server side. That would be a frickin' awesome methodology for this type of problem. Not sure if Firebug has that capability though. I still don't know what's setting this text. So my question is still up for grabs.

Imports System.Web
Imports System.Web.UI.WebControls

Public Class MyTextBox
    Inherits System.Web.UI.WebControls.TextBox

    Public Overrides Property Text() As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            MyBase.Text = value
        End Set
    End Property

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        MyBase.Render(writer)
    End Sub

End Class

In my page where I'm implementing this custom web server control, I need to register this class.

<%@ Register Assembly="Acu.LIMS.UI.Web" Namespace="Acu.LIMS.UI.Web" TagPrefix="MyTextBox" %>

<MyTextBox:MyTextBox id="txtKeywords" runat="server" Width="125px" AutoCompleteType="None" AutoComplete="False"></MyTextBox:MyTextBox>

Well, I'm not crazy! It's not server side code and it's not client side code causing this. It's Mozilla Firefox's > Options > Security > Remember password checkbox causing the problem. BUT I'M STILL CONFUSED. :-\

On the computer causing the issue, I kept toggling this checkbox, and could not get the browser to ask me the question, "Do you want Firefox to remember your password?" (don't remember the exact wording). But on another computer, I got asked immediately. And when I clicked "Remember" and went to that page, "x" shows in this input field (aka TextBox web control). Both my user name and password are both "x", so I'm not sure which it is pulling. Despite the value it pulls, my culprit TextBox doesn't have either id (of the user id or password) as it's id. Next question: How does Firefox determine when to fill in the username and password? One interesting thing about this form is that another field does have the password textbox, but I DO NOT have the user id in this form. I wonder if Firefox puts the user name in the first field it finds??

=======================

Answer

So I put in a dummy field in the SearchPanel control, and guess where my user name filled in. I was reading on this link about the Mozilla Password Manager, and apparently Mozilla uses its intelligence to determine the best place to put the user id (sometimes referred to as user name). In my case, I have a label for the user name (not the user id) in my Authentication control, but I don't want a user id field. Since the user is already logged in, they shouldn't be entering any user id. So that's why the user name label is in front of the password field. We audit changes in our application, so that is the purpose for having it inside the application.

https://wiki.mozilla.org/Firefox%3aPassword_Manager

So I did a test to validate Mozilla's functionality. I put another dummy field after the older culprit TextField (with id "txtKeywords", so that it's placement is the last input field preceding the password input field. And guess where Mozilla Firefox put the user id? Yep, in the dummy TextBox/input field. When I turn off the "Remember password for sites" option under Mozilla > Options > Security, it doesn't populate, nor does my password field. So this is my answer. I guess for now, I'll just put a hidden TextBox field in my Authentication control so Mozilla populates that one instead, but is not visible.

SearchPanel.ascx control:

<tr>
    <td nowrap class="categoryverticalNav">
        <asp:Label id="lblSearch" runat="server">Search</asp:Label><BR>
        <asp:DropDownList id="ddlCategory" runat="server" Width="164px"></asp:DropDownList><BR>
        <asp:TextBox id="txtKeywords" runat="server" Width="125px" AutoCompleteType="None" AutoComplete="False"></asp:TextBox>&nbsp;
        <asp:TextBox id="TextBox1" runat="server" Width="125px" AutoCompleteType="None" AutoComplete="False"></asp:TextBox>&nbsp;
        <asp:Button id="btnGo" runat="server" Width="28px" Text="Go" CausesValidation="False" />
    </td>
</tr>

Yep, putting in a hidden input field solved it. I suppose I could have either put in a TextBox also, but I just chose an input field with runat="server".. since the CLR doesn't need to interact with it in ASP.NET. Once I did that, the "x" (user id) disappeared from the SearchPanel control txtKeywords input field. :-)

<td>
    <b><asp:Label ID="LblUserDisplayName" Runat="server" EnableViewState="False"></asp:Label></b>
</td>
<td>Password</td>
<td>
    <input runat="server" type="text" style="display:none;">
    <asp:TextBox id="TxtPassword" Runat="server" Width="80" EnableViewState="False" TextMode="Password"></asp:TextBox>
</td>

解决方案

See the bottom of my question for the Answer. It's all explained. Essentially Mozilla Firefox Password Manager places the user id into the last input field preceding the stored input field (based on what's stored in the Mozilla Firefox Password Manager). So I'm just going to place a hidden dummy textbox (or input) field inside my Authentication control that precedes my password input field.

This article has one quote that sort of explains it, but I think I have a better explanation.

https://wiki.mozilla.org/Firefox%3aPassword_Manager

Quote from link above:
"Then uses the usernamefield/passwordfield values as hints to find the appropriate elements within a webpage by matching them to the "name" attribute."

这篇关于ASP.NET文本框(HTML输入字段)填充与用户名的形式自动负载时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆