Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use viewstate value in Javascript in asp.net??
Posted

1 solution

Use RegisterHiddenField than mixing server/js codes:

JavaScript:
XML
<script language="javascript" type="text/javascript">
    var vCode = document.getElementById("vCode");
alert(vCode);
</script>


Code behind:
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ViewState("code") = "EE"
    Page.ClientScript.RegisterHiddenField("vCode", ViewState("code"))
End Sub


For more have look on following threads:
Some CP Articles:
ASP.NET Internals: Viewstate and Page Life Cycle[^]
Beginner's Guide To View State [^]
Access ViewState Across Pages[^]

Other site:
Maintaining the ViewState[^]
ViewState in ASP.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900