Saturday 22 March 2014

access viewstate using javascript

What is View state ?
It is important and useful client side state management mechanism. It can store the page value at the time of post back. ASP.NET provides the ViewState property is built-in structure which automatically storing data between multiple requests for the same page.




Defining View State:
ViewState["Var"]=Count;
Retrieving information from View State
string Test=ViewState["TestVal"];

But to accessing the viewstate from client side code, access view state from javascript.


@Code snippet to access View State

<script language="javascript" type="text/javascript">
        var GetValue = document.getElementById("GetValue");
        alert(GetValue1);
    </script>


@Code in server side
ViewState["value"] = "Test View State";
            Page.ClientScript.RegisterHiddenField("GetValue", Convert.ToString(ViewState["value"]));
    

No comments:

Post a Comment