1

I can't seem to figure out why this isn't working. It is giving me this error "Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined"

  var timeoutID;

function delayedAlert() {
    document.getElementById('<%= Label3.ClientID %>').style.display = 'inherit';
        timeoutID = window.setTimeout(labelhide, 3000);
}

function labelhide() {
    document.getElementById('<%= Label3.ClientID %>').style.display = 'none';
}

button code

<asp:Button ID="Button1" runat="server"  Onclick = "Button1_Click" 
            OnClientClick = "javascript:delayedAlert(); return SubmitForm();" 
            Text="Submit" Width="98px"

This is my Label3

<asp:Label ID="Label3" runat="server" Text="Entry Successful!" Visible="False" ForeColor="Lime"></asp:Label>

This is what the new error says with the code above.. enter image description here

1 Answers1

3

The error occurs because the element Label3 could not be found. Please verify that you have ClientIDMode="Static" in the Label declaration. If not, you must use ClientID, like this:

document.getElementById('<%= Label3.ClientID %>').style.display = 'inherit';
nmat
  • 7,430
  • 6
  • 30
  • 43
  • I just set the CLientIDMode in the label declaration and it not working, I used the 2nd method as well and it doesn't work as well D: – user2484066 Jun 18 '13 at 21:06
  • @user2484066 ClientIDMode="Static" can only be used in .NET 4.0 or greater. The other alternative should work, don't forget to add it in both functions: delayedAlert and labelhide – nmat Jun 18 '13 at 21:08
  • @user2484066 that's unrelated to this problem. Anyway, try to clean/rebuild, this might also help: http://stackoverflow.com/questions/314329/getting-rid-of-there-is-no-source-code-available-for-the-current-location – nmat Jun 18 '13 at 21:15