Reputation: 31
I'm a newbie in programming thus do pardon me.
I have a .js game that outputs a variable called "score".
I require the variable to be able to be displayed on my asp label and after which grabbing its value for database storage onClick()
Currently what I have been able to do were:
@ .js:
document.getElementById('score').value = score;
@ .aspx:
<asp:Label runat="server" ID="score"></asp:Label>
The score is reflected on this label right now. However, I need to do a additional function which is to obtain the value of 'score' from the label and use it as a String in C#
Upvotes: 3
Views: 1659
Reputation: 41
Could you please try the below suggession.
document.getElementById('<%= lblScore.ClientID %>').innerHTML = 'Test Value';
document.getElementById('<%= hdnScore.ClientID %>').value = 'Test Value';
<asp:Label runat="server" ID="lblScore"></asp:Label>
<asp:HiddenField ID="hdnScore" runat="server" />
var score = hdnScore.Value;
Hope this will help you to fix the issue.
Upvotes: 1
Reputation: 148110
Use ClientID of server control as id score would have changed in the generated html by asp.
Change
document.getElementById('score').value = score;
To
document.getElementById('<%= score.ClientID %>').value = score;
Upvotes: 3