Click here to Skip to main content
13,097,230 members (56,152 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i want know why viewstate variable data updated on button click but not on page refresh in
Posted 2-Oct-12 23:44pm
Devang Vaja 3-Oct-12 5:47am
not clear question please elaborate it
Vijay Walunj,Navi mumbai 3-Oct-12 6:00am
i have one web page in this one button control i have added.i am for first time postback i am assing current date to one session variable.In pre render method i am asssigning it to viewstate variable.on button click i am matching this to variable value if it match i am changing session varible value to current time so now there is different time in session and viewstate variable.After buttonclick method executed prerender method is called in this viewstate varible value set to session variable value.if now i am click on submit button again i found that my viewstate and session varible values are same but in case of page refresh it not code is

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Session("Time") = Date.Now.ToString
End If
End Sub

Private Sub Statemanagement_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
ViewState("Time") = Session("Time")
End Sub

Protected Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

If ViewState("Time") = Session("Time") Then
Session("Time") = Date.Now.ToString
End If
End sub
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

When you click the refresh button of the browser it is sending a GET query to your web server. Then ASP.Net do not receive any viewstate information from the browser. It is considered as a totally new Request.
When you click a button on your page then the browser send a POST query to your server, this one will include the viewstate information from the browser.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100