2014-04-20 1 views
1

asp : DataList에 div가 있습니다. 여기에는 다른 div가 포함되어 있습니다. 나는 document.getElementByID("")에 의해 div를 찾으려고 노력했다. 자바에서 데이터 목록의 Div 찾기

그것이라고 : Unable to get property 'style' of undefined or null reference.

을 나는 .getElementById이 그것을 찾을 수 있음을 이해 결과. 그럼 어떻게받을 수 있습니까? 나는 오래된 자료로 나의 데이터리스트를 찾으려고 노력했지만 그 중 아무 것도 내 문제와 일치하지 않는다.

참고 : 내 divs은 드래그해야하지만,이 문제로 인해 위치 값을 얻을 수 없습니다.

코드 : 함수가 온로드라고

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; 

때문에 에러가 온로드 나타납니다.

HTML : 아이디는 HTML 문서에 한 번 나타나야로

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

오류를 나타내는 코드를 추가하십시오. – jgillich

+0

관련 HTML은 무엇입니까? 그리고 자바 스크립트? 우리가 당신의 문제를 볼 수 있다면 우리가 도울 수 있습니다. –

+0

editted .. 나는 그것이 충분히 분명하기를 바란다. 그렇지 않다면, 무엇을 말하면 깊이 설명하기 위해 최선을 다할 것입니다. – Quaion

답변

0

몇 가지 문제, 정적 ID를 가진 항목 템플릿을 채우기되어서는 안된다.

이러한 div에 클래스를 적용하고 이러한 div를 참조하는 것이 좋습니다.

페이지가 렌더링되면 마우스 오른쪽 버튼으로 클릭하고 이러한 요소 중 하나를 검사합니다. ASP는 데이터리스트의 일부인 ID에 여분의 접두어를 추가 할 수 있습니다 (예 : Visual Studio의 DivLabel1은 페이지가로드 된 후 DataList1_DivLabel1이됩니다). javascript가이 변환에 없으므로 클래스별로 이러한 항목을 참조하는 것이 좋습니다