I've encountered an issue with a div within an asp:DataList, which contains nested divs. My attempt to find these divs using document.getElementByID("")
resulted in the error message:
Unable to get property 'style' of undefined or null reference.
This led me to realize that the .getElementById
method was unable to locate them. So, I'm now seeking alternative methods to access these divs.
I've searched through old posts for solutions to my problem but none seem to align with my specific issue.
A critical aspect is that my divs
need to be draggable, and while they are successfully movable, I'm unable to retrieve their positional values due to this obstacle.
Below is the code snippet:
function FullDragging() {
// some code
var dd = document.getElementById("DesigningDiv"); // frame
var logoObject = document.getElementById("logoObject"); // draggable element
var nameObject = document.getElementById("nameObject"); // draggable element
function getDesigningDivSize() {
var dd = document.getElementById("DesigningDiv");
var aspDesigningDivHF = document.getElementById('<%=aspDesigningDivHF.ClientID %>'); // hidden-field which sends the changes in client-side to the server.
aspDesigningDivHF.value = parseInt(dd.style.width) + "," + parseInt(dd.style.height);
}
}
window.onload = FullDragging;
As the function is called onload, the error also occurs at this point.
Here's the relevant HTML structure:
<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" Height="400px" Width="1400px" OnEditCommand="DataList1_EditCommand" OnItemCommand="DataList1_ItemCommand" CellPadding="40" RepeatColumns="2" RepeatDirection="Horizontal" OnCancelCommand="DataList1_CancelCommand" OnItemDataBound="DataList1_ItemDataBound" OnUpdateCommand="DataList1_UpdateCommand">
<ItemTemplate> ... </ItemTemplate>
<EditItemTemplate>
<div id="DesigningDiv" style="height: 150px; width: 262.5px; border-style: groove; border-color: inherit; border-width: 1px; position: relative; height: 158px; width: 270px; background-color: #FFFFFF; visibility: hidden">
<div id="logoObject" style="width: 51px; top: 31px; position: absolute; height: 34px; font-family: 'times New Roman', Times, serif; font-size: xx-large; font-weight: bold; color: #333333; cursor: move; left: 187px;"> logo </div>
<div id="nameObject" style="width: 61px; top: 31px; position: absolute; height: 22px; font-family: 'times New Roman', Times, serif; color: #666666; font-size: large; cursor: move; font-weight: bold; left: 29px; bottom: 105px;"> full name </div>
</EditItemTemplate>
</asp:DataList>