I've encountered another issue after resolving the previous one
XML file reading problem: always the same result
While dynamically creating HTML elements and assigning values read from an XML file, the elements disappear right after creation. Any insights on why this might be happening? Below is the code snippet from my C# file:
script = "function OnClientDragEnd(dock, args)" +
"{" +
" req = false; " +
" var isIE = false;" +
// branch for native XMLHttpRequest object
" if(window.XMLHttpRequest && !(window.ActiveXObject)) {" +
" try {" +
" req = new XMLHttpRequest();" +
" } catch(e) {" +
" req = false;" +
" }" +
// branch for IE/Windows ActiveX version
" } else if(window.ActiveXObject) {" +
" try {" +
" req = new ActiveXObject('Msxml2.XMLHTTP');" +
" } catch(e) {" +
" try {" +
" req = new ActiveXObject('Microsoft.XMLHTTP');" +
" } catch(e) {" +
" req = false;" +
" }" +
" }" +
" }" +
" if(req) {" +
" req.onreadystatechange = function(){processReqChange(dock,args)};" +
" req.open('GET', 'Config.xml', false);" +
" req.send('');" +
" }" +
"}" +
"function processReqChange(dock,args) {" +
// only if req shows "loaded"
" if (req.readyState == 4) {" +
// only if "OK"
" if (req.status == 200) {" +
// ...processing statements go here...
" var contagemNos = req.responseXML.documentElement;" +
" var txt = contagemNos.childNodes(i).getElementsByTagName('Titulo')[0].text;" +//alert(txt);
" var ta = contagemNos.childNodes(i).getElementsByTagName('Id')[0].previousSibling; var tatext = ta.text;" +//alert(tatext);
" var ni = document.getElementById('spanObjDock');" +
" var divIdName = 'myDiv';" +
" var newdiv = document.createElement('div');" +
" newdiv.setAttribute('id',divIdName);" +
" var labelTitulo = document.createElement('label');" +
" labelTitulo.id = 'span1';" +
" labelTitulo.innerHTML = 'Title';" +
" newdiv.appendChild(labelTitulo);" +
" var break1 = document.createElement('br');" +
" newdiv.appendChild(break1);" +
" var tboxTitulo = document.createElement('input');" +
" tboxTitulo.setAttribute('type', 'text');" +
" tboxTitulo.setAttribute('value', txt);" +
" tboxTitulo.setAttribute('name', 'tboxTitulo');" +
" tboxTitulo.setAttribute('id', 'tboxTitulo');" +
" if (tboxTitulo.addEventListener){" +
" var enviar = 'tboxTitulo';" +
" tboxTitulo.addEventListener('keyup', function(){updateValueTitulo(enviar);}, false);" +
" } else if (tboxTitulo.attachEvent){ " +
" var enviar = 'tboxTitulo';" +
" tboxTitulo.attachEvent('onkeyup', function(){updateValueTitulo(enviar);});" +
" }" +
" newdiv.appendChild(tboxTitulo);" +
" var break1 = document.createElement('br');" +
" newdiv.appendChild(break1);" +
" ni.appendChild(newdiv);" +
" } else {" +
" alert('There was a problem retrieving the XML data: ' + req.statusText);" +
" }" +
" }" +
"}";
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "PositionChanged", script, true);
This snippet shows the code in my ASP.NET file:
....
<asp:UpdatePanel runat="server" id="UpdatePanel3">
<ContentTemplate>
<div id="spanObjDock"></div>
</ContentTemplate>
</asp:UpdatePanel>
....