Reputation: 41
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..
Upvotes: 1
Views: 2064
Reputation: 7591
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';
Upvotes: 3