Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
hi
i want know why viewstate variable data updated on button click but not on page refresh in asp.net
Posted 2-Oct-12 23:44pm
Comments
Devang Vaja at 3-Oct-12 5:47am
   
not clear question please elaborate it
Vijay Walunj,Navi mumbai at 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 same.my 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
MsgBox("Match")
Session("Time") = Date.Now.ToString
End If
End sub
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 339
1 Maciej Los 208
2 George Jonsson 144
3 Kornfeld Eliyahu Peter 139
4 Dave Kreskowiak 130


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