473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Basic Q: Page variables

This is a basic question. Does Page related member variable values
only be set in the Page they are executed? Example code like below

public partial class _Default : System.Web.UI.Page
{
string var = "";

protected void BtnSubmit_Click(object sender, EventArgs e)
{
if (Select.Checked)
{
var = "Visited";
tbox.Text = "Selected On " + var;
}
else
tbox.Text = "Selected Off " + var;
}
Variable var is set to value 'Visited' ONLY in web page that is executed by
submit.
Not in other instances of same page executed in other page instances in
other Browser instances.

What I like to know that does Page instance differ in this case from Java's
Servlet member variables
that are shared with all instances.

Cheers!

Dec 4 '06 #1
2 1174
The page class is like any other class. Any variables defined in it, are
tied to an instance of the class. If you wanted to have the variable be
shared among all instance, you would have to declare it as 'static'.

"Jimmy" <ji***@spam.nowrote in message
news:el**********@nyytiset.pp.htv.fi...
This is a basic question. Does Page related member variable values
only be set in the Page they are executed? Example code like below

public partial class _Default : System.Web.UI.Page
{
string var = "";

protected void BtnSubmit_Click(object sender, EventArgs e)
{
if (Select.Checked)
{
var = "Visited";
tbox.Text = "Selected On " + var;
}
else
tbox.Text = "Selected Off " + var;
}
Variable var is set to value 'Visited' ONLY in web page that is executed
by submit.
Not in other instances of same page executed in other page instances in
other Browser instances.

What I like to know that does Page instance differ in this case from
Java's Servlet member variables
that are shared with all instances.

Cheers!



Dec 4 '06 #2
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
The page class is like any other class. Any variables defined in it, are
tied to an instance of the class. If you wanted to have the variable be
shared among all instance, you would have to declare it as 'static'.
It would then require synchronization to prevent it being updated by
multiple threads simultaneously.

Writable static member variables are usually a bad idea in web pages.

John
Dec 4 '06 #3

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

Similar topics

2
by: Japhy | last post by:
Hello, I am writing my first website using PHP/MYsql. I bought some PHP templates to help (from SoftVelocity). Basically, so far, my application first pulls up a table of key values from the DB. ...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
6
by: Jimmy Clay | last post by:
I have a very basic question about how to include files to be used by another file. I'm trying to include a bad word filter into the guestmap on my website. I know almost nothing about PHP code....
2
by: Brett Porter | last post by:
Relatively new to ASP.Net but have a strange problem. My site uses forms authentication for a large administration section however after the user logs in each page they subsequently click on...
3
by: darrel | last post by:
This is something I should know, but I don't. Say I have this: Function dim variable1 dim variable2 do stuff with the variables
0
by: CrAn57 | last post by:
I'm using Visual Studio .net, and am programming a web form in Visual Basic (including the HTML page, and the VB code behind page). I have a flash .swf on the HTML side of the page, but want to...
4
by: Richard Carpenter | last post by:
Considering a typical scenario where the user is presented a list of customers and, upon selecting one and clicking a button, they are then presented with a new page depicting the orders for that...
4
by: Goran Djuranovic | last post by:
Hi all, I am experiencing a strange thing happening with a "designer.vb" page. Controls I manually declare in this page are automatically deleted after I drop another control on a ".aspx" page. -...
1
by: Ronm | last post by:
Hey Guys, I have a problem which has been driving me crazy for the last days. I'm working on a small project involving: Visual Basic Acces Database ASP and adobe/macromedia Flash,
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.