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

0

I am working on an application, where I provide user with an option to change the base year only when he/she enters the right password, I do that by using a modal popup extender:

if the password matches then set readonly to false on the textbox else provide an error message in the panel.

<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>

This is the script that gets fired when the user clicks okay:

<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 runtime error: Unable to set property 'value' of undefined or null reference

I am getting an error when I set the label with ID="error" to display the error message please help!!!! I even tried innerHtml I am using (IE).Also why Does the modal close after it hits the else statement???

javascript
c#
asp.net
label
modalpopupextender
asked on Stack Overflow Mar 29, 2016 by CodeMan • edited Mar 29, 2016 by CodeMan

1 Answer

0

You can't keep modal popup open after postback since the modal is opened from client script ( I think so ) , but you can call from server another open command.

this post may help : here

answered on Stack Overflow Mar 29, 2016 by Ermir Beqiraj • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0