473,795 Members | 2,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access a page level variable from within a class instance

Is there a way for an instance of a custom class to access an ASPX page
level variable? I know that I can access a Session variable from
within a class using the following code:

myClassVar =
System.Web.Http Context.Current .Session.Item(" mySessionVar")

But I can't figure out if it is possible to access a page level
variable from within a class.

For example, let's say I had the following code for my ASPX page:

Public Class myPage
Inherits System.Web.UI.P age

Public myPageVar as String

Private Sub Page_Load (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myPageVar = "My Test"
Dim myObject as New myClass()

End Sub
End Class

And that I had the following code for a custom class:

Public Class myClass

Private _localVar as String

Public Sub New()
MyBase.New()
_localVar = ????????? (How do I access the variable myPageVar on
the ASPX page?)
End Sub

End Class

Any help would be greatly appreciated.

Thanks,
Corey

May 23 '06 #1
2 1937
you have a couple options.

1) pass the variable on the constructor
2) have the aspx page implement an interface, and pass the interface to
class.
3) pass the page instance to the class and use reflection

-- bruce (sqlwork.com)

"Corey B" <co***********@ gmail.com> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
Is there a way for an instance of a custom class to access an ASPX page
level variable? I know that I can access a Session variable from
within a class using the following code:

myClassVar =
System.Web.Http Context.Current .Session.Item(" mySessionVar")

But I can't figure out if it is possible to access a page level
variable from within a class.

For example, let's say I had the following code for my ASPX page:

Public Class myPage
Inherits System.Web.UI.P age

Public myPageVar as String

Private Sub Page_Load (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myPageVar = "My Test"
Dim myObject as New myClass()

End Sub
End Class

And that I had the following code for a custom class:

Public Class myClass

Private _localVar as String

Public Sub New()
MyBase.New()
_localVar = ????????? (How do I access the variable myPageVar on
the ASPX page?)
End Sub

End Class

Any help would be greatly appreciated.

Thanks,
Corey

May 23 '06 #2
Yeah I was trying to avoid passing anything to the class (either in the
constructor or otherwise). I am implementing my own XML serialization
for the class and the serialization engine seems to need a
parameterless constructor for the serialization to work. I just wasn't
sure if there was some built in way that a class could reference a
variable on the page where the class was instantiated.

Corey

May 23 '06 #3

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

Similar topics

3
2481
by: Brian Munroe | last post by:
I am just starting to learn the OO side of Python scripting, and I am a little confused on the following. Take the following example class: >>> class rectangle(object): z = 1 def __init__(self): self.x = 2 >>> r = rectangle() >>> print r.z
166
8681
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
14
5423
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB 7.2 environment, the choices the optimizer makes often seem flaky. But this last example really floored me. I was hoping someone could explain why I get worse response time when the optimizer uses two indexes, than when it uses one. Some context:
9
4162
by: Clint | last post by:
Hey all - Excuse the cross-post ... I'm not sure what the appropriate newsgroup would be for this question. I have a question that I'm not quite sure how to ask. For all I know, I have the verbaige completely wrong, but here goes nothing ... I'm currently using the MS Data Access Block for a desktop application I'm writing. Recently, I had to add a call to a web service, which in
8
9206
by: hb | last post by:
Hi, I need to declare a variable who's value can be preserve through the same ASP.Net page. I tried the following code, only the static variable s2 keeps its value=22 after lnk1_Click followed by lnk2_Click(). The others return to their original values initiated during their declaration. But the static variable's life doesn't end when the page is closed and it causes
2
2358
by: Jon Hyland | last post by:
This might be a dumb question, but what is the best way for one instance of a user control to access properties of an instance of another user control? For example, let's say I have an instance of UserControlA (ucA1) and an instance of UserControlB (ucB1) on a particular ASP.NET page. UserControlA has a string property called StringA that gets generated from a DB call in it's Page_Load event. I want UserControlB to be able to access...
37
2609
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
4
343
by: Diffident | last post by:
Hello All, I have a question which is pertinent to Page's lifecycle. I declared a protected static object (global variable within that class) whose value is set only once when the page is loaded. Will that object's value be accessible during consequent postbacks or is it set to null after HTML is rendered initially?
9
2166
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service) Hide.dll methods and data I want to remain hidden I have a DLL, Hide.dll, that contains methods that I want to handle for
0
9672
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
9519
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
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
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
6783
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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...
2
3727
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.