无法从JS中的getValue获取值,并且无法在showValue字段中显示值。
提前致谢
ASPX PAGE CODE
<script>
var x = document.getElementById("<%=getValue.ClientID %>").innerHTML;
document.getElementById('showValue').innerHTML = x;
</script>
<asp:Label runat="server" ID="getValue" />
<asp:Label runat="server" ID="showValue" />
C#CODE
getValue.Text = "value from code";
答案 0 :(得分:1)
一旦呈现所有控件,您需要调用javascript,然后只有您可以获得&lt; asp:label&gt;的正确ID。控制,所以你需要在window.onload()下编写那个javascript代码。
同样对于showValue,您需要使用ClientID。
window.onload= function(){
var x = document.getElementById("<%=getValue.ClientID%>").innerHTML;
document.getElementById('<%=showValue.ClientID %>').innerHTML = x;
};