473,386 Members | 1,754 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,386 software developers and data experts.

reference to a "global" variable from within an aspx page

Hello,

In an aspx page (mypage.aspx) from a web projet,
I would like to get the value of a variable of the projet that is declared
as public in a module.
The variable can be called from anywhere in the code behind page and in the
class files, but when I try to call it from an aspx page, it raises an
error.

<%=myvar%> in mypage.aspx raise an error : the name "myvar" is not declared.

I have a workaround, but it does not satisfy me enough :

I create a code behind for the aspx page and I declared a class variable,
let's say "cls_myvar", with a default value equals to "myvar".
And now when referencing the "cls_myvar" in the aspx page, there is no error
and the value is here.

<%=cls_myvar%> is ok.

But I would like to reference to the global var "myvar" in the simpliest
way, ie whithout having to create a code behind file.

Thanks for any help.

Pierre.
Jan 13 '06 #1
3 3917
Dan
Hi Pierre,

Personally one of the best features of .net is that we can now pull just
about every bit of code out of the form page itself so that web designers
and programmers can both work on what they do best. I have made so many
large sites and never needed to write <% =myVar %> , not since asp anyway.

Whatever it is you are setting to that value surely can be done on the code
behind with no need to go into the html?

Anyway i think your missing an understanding of classes. You said that you
set the var to public in the class, this makes that var public to everything
in that class and anything else from outside that makes an instance of that
object, in other words you haven't made a application global var, you have
made a class global var.

What you want to be doing is make an application global var in your
global.asx (thats what it is there for). Once you do this every aspx page
will be able to reference the global var.

I would then reference that global var in my code behind files to set values
in the page. I get the impression you prefer not to use the code behind
file? Why?

Anyway i hope that helps

--
Dan
"Pierre" <pi*******@freesurf.fr> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello,

In an aspx page (mypage.aspx) from a web projet,
I would like to get the value of a variable of the projet that is declared
as public in a module.
The variable can be called from anywhere in the code behind page and in
the class files, but when I try to call it from an aspx page, it raises an
error.

<%=myvar%> in mypage.aspx raise an error : the name "myvar" is not
declared.

I have a workaround, but it does not satisfy me enough :

I create a code behind for the aspx page and I declared a class variable,
let's say "cls_myvar", with a default value equals to "myvar".
And now when referencing the "cls_myvar" in the aspx page, there is no
error and the value is here.

<%=cls_myvar%> is ok.

But I would like to reference to the global var "myvar" in the simpliest
way, ie whithout having to create a code behind file.

Thanks for any help.

Pierre.

Jan 13 '06 #2
Global's values can be seen by every user, so that is a no no.

"Pierre" <pi*******@freesurf.fr> schreef in bericht
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello,

In an aspx page (mypage.aspx) from a web projet,
I would like to get the value of a variable of the projet that is declared
as public in a module.
The variable can be called from anywhere in the code behind page and in
the class files, but when I try to call it from an aspx page, it raises an
error.

<%=myvar%> in mypage.aspx raise an error : the name "myvar" is not
declared.

I have a workaround, but it does not satisfy me enough :

I create a code behind for the aspx page and I declared a class variable,
let's say "cls_myvar", with a default value equals to "myvar".
And now when referencing the "cls_myvar" in the aspx page, there is no
error and the value is here.

<%=cls_myvar%> is ok.

But I would like to reference to the global var "myvar" in the simpliest
way, ie whithout having to create a code behind file.

Thanks for any help.

Pierre.

Jan 13 '06 #3
Hello hello

Thank you for taking care af my OOP knowledge.
The pratical case is :
a plateform used localy for developpement (http://localhost/project), and
accedeed remotly by the custumer (http://www.dummy.com/project). Javascript
is used in the pages, with CSS and Images.
As you know (because you may know a lot of things, included the OOP), there
is some issues regarding the path to access to the CSS and images from the
javascript. In other word, there is a need for absolute url. The global var,
then, is dedicated to set the path dynamically in the url string inside the
CSS and the javascript file according to the access type : localy or
remotely.
As I do not want to build a gas factory to solve this issue that is raised
only during the dev, I just need a simple global var for that, temporary.
So everthing else is superfetatoire my dear.

See you.

Pierre.

"Pierre" <pi*******@freesurf.fr> a écrit dans le message de news:
%2****************@TK2MSFTNGP11.phx.gbl...
Hello,

In an aspx page (mypage.aspx) from a web projet,
I would like to get the value of a variable of the projet that is declared
as public in a module.
The variable can be called from anywhere in the code behind page and in
the class files, but when I try to call it from an aspx page, it raises an
error.

<%=myvar%> in mypage.aspx raise an error : the name "myvar" is not
declared.

I have a workaround, but it does not satisfy me enough :

I create a code behind for the aspx page and I declared a class variable,
let's say "cls_myvar", with a default value equals to "myvar".
And now when referencing the "cls_myvar" in the aspx page, there is no
error and the value is here.

<%=cls_myvar%> is ok.

But I would like to reference to the global var "myvar" in the simpliest
way, ie whithout having to create a code behind file.

Thanks for any help.

Pierre.

Jan 13 '06 #4

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

Similar topics

11
by: mrbog | last post by:
I have an array/hash that stores path information for my app. As in, what directory this is in, what directory that's in, what the name of the site is, what the products are called, etc. It's...
7
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global"...
9
by: Javaman59 | last post by:
I saw in a recent post the :: operator used to reach the global namespace, as in global::MyNamespace I hadn't seen this before, so looked it up in MSDN, which explained it nicely. My question...
4
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public...
5
by: dave | last post by:
If I have a class that hold, for instance, user settings that should be accessible to the entire program logic, what is a good paradigm to use? In C++, I would have made it a global object,...
2
by: Paul | last post by:
I am taking over an exisitng app. I have the following function on one page: function check($v) { global $user; return $user->validate($v, $v); } And it reference $user on the next page. ...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
1
by: sap0321 | last post by:
This should be kindergarten stuff but for some reason I am having trouble with it. I do 99.9% web programming and this is the first windows app i've done in years - probably the first ever in C# ......
4
ChrisWang
by: ChrisWang | last post by:
Hi, I am having trouble understanding the use of 'global' variables I want to use a global variable with the same name as a parameter of a function. But I don't know how to use them at the same...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.