Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 23rd, 2005, 06:59 AM
Authorized User
 
Join Date: Mar 2004
Location: Ahmedabad, Gujarat, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mistry_bhavin
Default Save variable's value between page roundtrip

Dim i As Int16

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        If (Not IsPostBack) Then
            i = 10
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Write(i)
    End Sub


When I write this kind of stuff I get 0 as a value of i.
But if i do not write i = 10 inside the if(not ispostback) then
i get proper value.
So is it nessary to set value for variables every time I load the page? Is't there any way to store variables permanantly, which can
hold their values between page roundtrips?

  #2 (permalink)  
Old August 23rd, 2005, 11:24 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Where is the variable i declared????

  #3 (permalink)  
Old August 23rd, 2005, 11:39 AM
Authorized User
 
Join Date: Mar 2004
Location: Ahmedabad, Gujarat, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mistry_bhavin
Default

I is Globaly declared before Page_Load procedure.

  #4 (permalink)  
Old August 23rd, 2005, 12:10 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You can store them in ViewState so they survive postbacks:

In Page_Load:
Code:
i = 10
ViewState("MyVar") = i
Then in Button1_Click:
Code:
If Not ViewState("MyVar") Is Nothing Then
  i = Convert.ToIn16(ViewState("MyVar"))
End If
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
  #5 (permalink)  
Old August 24th, 2005, 02:31 AM
Friend of Wrox
 
Join Date: May 2003
Location: Delhi, Delhi, India.
Posts: 230
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can also use session to store.

Charul Shukla
  #6 (permalink)  
Old September 3rd, 2005, 03:47 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cairo, , Egypt.
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

viewstate is prefeared than session when doing postback in the same page

Ahmed Ali
Software Developer
  #7 (permalink)  
Old September 3rd, 2005, 08:03 AM
Friend of Wrox
Points: 410, Level: 7
Points: 410, Level: 7 Points: 410, Level: 7 Points: 410, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: New Delhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

 Basically variables which are needed across different page visits (navigation) are to stored in session while viewstate is preffered for page level variables which are excessed across the page visit of the same page( post back)

Anubhav Kumar
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to refresh page after save dialog derickloo ASP.NET 1.0 and 1.1 Basics 0 December 13th, 2007 11:43 PM
How do you save an html page on your local hd? rsalah Javascript How-To 16 January 27th, 2005 01:48 AM
blocking roundtrip javascript jaisonkmathews General .NET 3 November 27th, 2004 12:20 AM
Save the Confirmation Page as a file kelcontech Classic ASP Basics 8 May 13th, 2004 08:32 AM
html page save to excel format mateenmohd Javascript 2 January 17th, 2004 05:48 AM



All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.