使用Javascript在模态内部的标签上显示错误消息不起作用

using Javascript to display error message on label inside a modal not working

本文关键字:显示 错误 消息 不起作用 标签 Javascript 模态 内部 使用      更新时间:2023-09-26

我正在开发一个应用程序,在该应用程序中,我为用户提供了一个选项,只有当他/她输入正确的密码时,才能更改基准年,我使用模式弹出扩展程序:

如果密码匹配,则在文本框中将readonly设置为false,否则在面板中提供错误消息。

<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" Width="233px" BackColor="White" >
        <p>Password</p>
        <br />
        <asp:TextBox ID="password" runat ="server"></asp:TextBox>
         <br />
        <label id="error" runat="server"></label>
      <div>
      <asp:Button ID="OkButton" runat="server" Text="OK" />
      <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
   </div>
        <br />
        <p>If you do not know the password, you may contact a supervisor to receive the password</p>
    </asp:Panel>

这是当用户点击OK时被触发的脚本:

<script type="text/javascript">
 function onOk() {
 var value = document.getElementById
('<%=password.ClientID%>').value;
 var password = '<%=ConfigurationManager.AppSettings
["UnlockPassword"].ToString() %>'
  if (value == password)
    {
   document.getElementById
  ('<%=TxtBase.ClientID%>').readOnly = false;
    }
  else
  {
  document.getElementById
  ("error").value = "Incorrect Password Please Try Again";
        }
    }
</script>

0x800a138f-JavaScript运行时错误:无法设置未定义或null引用的属性"value"

当我设置ID为"error"的标签以显示错误消息时,我遇到了一个错误,请帮助!!!!我甚至尝试过innerHtml我正在使用(IE)。还有为什么模态在命中else语句后关闭???

您不能在回发后保持模式弹出窗口打开,因为模式是从客户端脚本打开的(我认为是这样),但您可以从服务器调用另一个打开命令。

这篇文章可能会有所帮助:在这里