473,763 Members | 6,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global Variables / Masterpages (2.0)

Hi Everybody!
I'm stuck with the following problem:

I have a couple of pages which has all the same 'header', i.e. some common
elements. So far I realized that the best thing would be to use master
pages. This is all fine and works.

Now, there are certain variables stored in the session object which I would
like to use in the other pages. What I would like to do is to initialize the
variables, assign values to them in the Page_Load of the MasterPage and then
use in the other pages (outside the masterpage, i.e., in the pages which use
the MasterPage). Is there any smart way to do this?

Thank you very much in advance,

Thiery
Aug 9 '06 #1
2 2292
You just described a "smart way". - Try and see how it works.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Thiery Balser" wrote:
Hi Everybody!
I'm stuck with the following problem:

I have a couple of pages which has all the same 'header', i.e. some common
elements. So far I realized that the best thing would be to use master
pages. This is all fine and works.

Now, there are certain variables stored in the session object which I would
like to use in the other pages. What I would like to do is to initialize the
variables, assign values to them in the Page_Load of the MasterPage and then
use in the other pages (outside the masterpage, i.e., in the pages which use
the MasterPage). Is there any smart way to do this?

Thank you very much in advance,

Thiery
Aug 9 '06 #2
Sure, creating public properties on your master page, and use the MasterType
directive.

So in your page, if you do:

<%@ masterType VirtualPath="~/template/main.master" %>

you can then access your master's properties in a strongly-typed fashion in
your page

int userId = Master.UserId;

Karl

ur master would look soemthing like:

private int _userId;
public int UserId
{
get { return _userId; }
}

Page_Load(...)
{
_userId = (int)Session["userId"];
}

--
http://www.openmymind.net/
http://www.codebetter.com/
"Thiery Balser" <th***********@ gmx.netwrote in message
news:44******** **@news.bluewin .ch...
Hi Everybody!
I'm stuck with the following problem:

I have a couple of pages which has all the same 'header', i.e. some common
elements. So far I realized that the best thing would be to use master
pages. This is all fine and works.

Now, there are certain variables stored in the session object which I
would like to use in the other pages. What I would like to do is to
initialize the variables, assign values to them in the Page_Load of the
MasterPage and then use in the other pages (outside the masterpage, i.e.,
in the pages which use the MasterPage). Is there any smart way to do this?

Thank you very much in advance,

Thiery

Aug 9 '06 #3

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

Similar topics

10
17879
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can overwrite another copies global variable? I know that you could overwrite a value in a global variable from a function, but you could also do that if you pass the variable in and then out again... so how is that any different?
4
24184
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); function loadUrlVariables() { varString = location.search;
17
5630
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm constantly running tests on imperfect code. On of the cumbersome jobs encountered is reassigning global vars their values after a close encounter with an untrapped runtime error. Rather than writing a procedure to simply reassign them all with a...
33
3049
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have been for years. If the machine has memory to spare and windows can use it - I'm thinking "Why not?" I was wondering what some of you have to say about that, particularly any severe "gotchas" you've had the unfortunate experience to contend with.
6
1769
by: Kenneth Keeley | last post by:
Hi, I have a Masterpage that controls the basic layout of the pages displayed on a web site. The masterpage also uses some variables. I would like to be able to access some of these variables from the content pages. Can this be done and if so how. I have made the Varibles that I wish to access Public Members. Thanks for any help. Kenneth
9
8656
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the following: '-----Begin module code
5
11826
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global $MYVAR, $a; ?>
1
29378
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
112
5471
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 that may print some messages. foo(...) { if (!silent)
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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 we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.