Reputation: 2560
I have a div
and inside this div, a ContentPlaceHolder
, and inside the holder a Linkbutton
.
I am trying to remove the link button dynamically but I am getting this error:
Error: DOM Exception: NOT_FOUND_ERR (8).
Here is my code:
<div id="leftcol" style="z-index: 0">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
<asp:LinkButton CssClass="childLI" ID="tblRSManswers" runat="server" Text="RS Manswers" OnClick="ChildLink_Click" >
Javascript code:
var child = document.getElementById("tblRSManswers"));
alert(child);
var parent = document.getElementById("ContentPlaceHolder2"));
alert(parent);
parent.removeChild(child);
P.S: The alerts are not NULL.
Upvotes: 0
Views: 97
Reputation: 22619
Try this code
document.getElementById("<%= tblRSManswers.ClientID %>").parentNode.removeChild(document.getElementById("<%= tblRSManswers.ClientID %>"));
Update:
In ASP.Net ContentPlaceHolders are just a placeholder to render some HTML elements, but its not an actual DOM element. It will not be visible in page. So finding content place holder with javascript always returns null, since it will not be rendered in DOM
Upvotes: 1
Reputation: 129802
removeChild
expects an immediate parent. Your pasted HTML seems to be only excerpts of the most relevant code, so even though it looks like it in your code, I'm not sure this is the case in your real application?
Try
child.parentNode.removeChild(child);
Upvotes: 3