473,508 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable Scope on the Page

hi,

can any body tell me why the variable loses its value,
i m actually declaring a variable which is public, and assigning a
values in Function1 and reading the values in Function2

following is a sample code for wht i m doing.
---------------------------------------
Public Class SupportRequest
Inherits System.Web.UI.Page
Dim Var1 As Integer
..
..
Private function Function1
Var1=1
End Function

Private Function Function2
'Var1 returns 0
Textbox1.text= Var1
End Function

End Class
-------------------------------------------
I call Function1 on click of Button1.
and Function2 at click of Button2.

regards.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
1 1176
Remember, the web is inherently stateless. That means every page view is
like a brand new occurance of the page. The variables and data is generally
not kept. You have to store the variable somewhere to handle this sort of
thing. Luckily, ASP.Net has the Viewstate. You can store the variable in the
viewstate after you perform some work on it in button one, then retrieve it
in button 2 (and do some work with it again and store it, etc..). Whenever
you access a Viewstate item you'll need to check if it is null first, just
to make sure because if you haven't saved the variable to the viewstate then
it will come back as null and possibly mess up your code.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Raheel Hussain" <ra*******@yahoo.com> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
hi,

can any body tell me why the variable loses its value,
i m actually declaring a variable which is public, and assigning a
values in Function1 and reading the values in Function2

following is a sample code for wht i m doing.
---------------------------------------
Public Class SupportRequest
Inherits System.Web.UI.Page
Dim Var1 As Integer
..
..
Private function Function1
Var1=1
End Function

Private Function Function2
'Var1 returns 0
Textbox1.text= Var1
End Function

End Class
-------------------------------------------
I call Function1 on click of Button1.
and Function2 at click of Button2.

regards.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1432
by: Joe Blow via DotNetMonster.com | last post by:
Hello, I have a design problem involving class instances as global variables. To give you my background, I've programmed lots in Java, and most of it has been large class structures. I'm...
10
2526
by: Brian | last post by:
If i declare a module level oledbconnection with each request for the page, the variable remains in scope? I get open.executing error message on subsequent calls for the page. I assumed ASP.Net...
23
19133
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
6929
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
3
1652
by: anuragpj | last post by:
i have designed a login page like this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Electrical Engineering Dept...
1
25621
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
35189
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
5
6113
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request...
112
5350
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
2
2888
by: ray | last post by:
Hi, all, foreach($array as $k =$v) { $foo = ...; } echo $foo; Is it allowed to access the $foo variable that is created within the loop from outside of the loop? I think it isn't allowed,...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.