Hello all, I have a quick question. I have the following javascript code Note the asp label at the end <script type = "text/javascript"> function loadTest(VEMap1){ alert("test"); }// end zoom function endZoom(e) { alert(e.view.zoomLevel); document.getElementById(Label1).value = e.view.zoomLevel; }// end end zoom </script> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> When my function endZoom is called I want Label1's text to change to e.view.zoomLevel. What am I doing wrong here Thanks Mike
Remove the "runat=server" You're attempting to use the label as if it were a static HTML element, but you can't do that with the runat=server. And you may have to use .innerHTML instead of .value
The problem with taking out the runat = "server" is that runat = "server" is required for the control is there any other way
I solved my problem The correct code is <script type = "text/javascript"> function loadTest(VEMap1){ alert("test"); }// end zoom function endZoom(e) { alert(e.view.zoomLevel); document.getElementById('<%=Label1.ClientID %>').innerText = e.view.zoomLevel; }// end end zoom </script> <asp:Label ID="Label1" runat = "server" Text="Label"></asp:Label>
Yes, use an ordinary <div id="swapDiv" style="display:none"></div>, using innerHTML to insert text, later. Use CSS, position.absolute to put the div above the Label. #swapDiv { position:absolute; top: 150px; left: 300px; } <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> Use JavaScript to, hide the Label, and display the div: document.getElementById('swapDiv').style.display = ""; document.getElementById('Label1').style.display = "none"; document.getElementById('swapDiv').innerHTML = "New Label Text"; You can use JS to test which way you need to go: if (document.getElementById('swapDiv').style.display == "none") { document.getElementById('swapDiv').style.display = ""; } Yes, the empty string is correct. Using an empty string to display elements ensures that it displays with its default property. A div is a block element. So, using "" ensures that it will display as expected, and not inline. A label is an inline element, but the same applies, use an empty string to display it, and "none" to hide it.