admin管理员组文章数量:1026423
Here is the control on the aspx page:
<asp:HiddenField ID="hdnGOfromLocalStorage" runat="server" Value="-1" />
Here is the code that is not working in Typescript:
let xxx: string = document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>');
Here is the control on the aspx page:
<asp:HiddenField ID="hdnGOfromLocalStorage" runat="server" Value="-1" />
Here is the code that is not working in Typescript:
let xxx: string = document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>');
Share
Improve this question
edited Nov 17, 2024 at 11:13
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Nov 17, 2024 at 0:04
RotoRoto
6052 gold badges5 silver badges18 bronze badges
1 Answer
Reset to default 1Your expression and code does not really make sense, since you attempting to assign the value to itself???
Your question is one of you attempting to get a value from the hidden field, not set a value.
Hence the following code should work:
<asp:HiddenField ID="hdnGOfromLocalStorage" runat="server" Value="-1" />
<asp:Button ID="cmdTest" runat="server" Text="Show Hidden value"
OnClientClick="mytest();return false;" />
<script>
function mytest() {
var MyValue
MyValue = document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>').value
alert("Value of hidden field = " + MyValue)
}
</script>
And when we run the above, we see this:
So, your expression does not retrieve any value, and looks to be an attempt to "assign" a value to the hidden field, which of course is a different question.
To assign a value to the hidden field, the following code would work:
document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>').value = "Hello world"
Here is the control on the aspx page:
<asp:HiddenField ID="hdnGOfromLocalStorage" runat="server" Value="-1" />
Here is the code that is not working in Typescript:
let xxx: string = document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>');
Here is the control on the aspx page:
<asp:HiddenField ID="hdnGOfromLocalStorage" runat="server" Value="-1" />
Here is the code that is not working in Typescript:
let xxx: string = document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>');
Share
Improve this question
edited Nov 17, 2024 at 11:13
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Nov 17, 2024 at 0:04
RotoRoto
6052 gold badges5 silver badges18 bronze badges
1 Answer
Reset to default 1Your expression and code does not really make sense, since you attempting to assign the value to itself???
Your question is one of you attempting to get a value from the hidden field, not set a value.
Hence the following code should work:
<asp:HiddenField ID="hdnGOfromLocalStorage" runat="server" Value="-1" />
<asp:Button ID="cmdTest" runat="server" Text="Show Hidden value"
OnClientClick="mytest();return false;" />
<script>
function mytest() {
var MyValue
MyValue = document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>').value
alert("Value of hidden field = " + MyValue)
}
</script>
And when we run the above, we see this:
So, your expression does not retrieve any value, and looks to be an attempt to "assign" a value to the hidden field, which of course is a different question.
To assign a value to the hidden field, the following code would work:
document.getElementById('<%= hdnGOfromLocalStorage.ClientID %>').value = "Hello world"
本文标签: How do I get the the value of an ASPNET hiddenfield in a typescript fileStack Overflow
版权声明:本文标题:How do I get the the value of an ASP.NET hiddenfield in a typescript file - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745641466a2160775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论