【问题标题】:Show/hide password inside UpdatePanel asp.net在 UpdatePanel asp.net 中显示/隐藏密码
【发布时间】:2018-09-12 01:20:44
【问题描述】:

我试图在 asp.net 的 UpdatePanel 中显示/隐藏密码。我已指定使用 AsyncPostBackTrigger 作为:

<asp:AsyncPostBackTrigger ControlID="chkRegister" EventName="CheckedChanged" />

我还为 UpdatePanel 使用了 UpdateMOde="Conditional":

<asp:UpdatePanel ID="UpdatePanelRegister" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">

最后,我为复选框设置了 AutoPostBack="true":

<asp:CheckBox ID="chkRegister" class="chk" runat="server" AutoPostBack="true" OnCheckedChanged="chkRegisterCheckedChanged"/>

“chkRegisterCheckedChanged”调用了一个我检查过的 JavaScript 函数,它正在被调用。 JS 是简单地显示或隐藏密码字段内的文本:

function showPassword() {
var x = document.getElementById("txtPasswordReg");
if (x.type === "password") {
    x.type = "text";
} else {
    x.type = "password";
}

}

问题在于,它实际上不是显示密码,而是清除字段(也许是完整的回帖?)。 关于如何解决这个问题的任何想法?

提前感谢您的帮助。

【问题讨论】:

    标签: javascript asp.net updatepanel


    【解决方案1】:
    <input type="text" id="txtPasswordReg" type="password" value="testPassword">
    <button onclick="ToggleShowPassword()">Toggle Password</button>
    <script>
    function ToggleShowPassword() {
        var x = document.getElementById("txtPasswordReg");
        if (x.type == "password") {
            x.type = "text";
        } else {
            x.type = "password";
        }
    }
    </script>
    

    这个功能确实有效。我不知道你为什么会遇到这个问题

    JSFiddle

    【讨论】:

    • @Kieram,是的,JS 工作正常。它似乎与asp UpadatePanel有关。不过感谢您的回复。我很感激。
    猜你喜欢
    • 2021-12-01
    • 2013-12-04
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2013-11-14
    • 2018-08-13
    • 2019-10-15
    相关资源
    最近更新 更多