By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,877 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,877 IT Pros & Developers. It's quick & easy.

Accessing variables of another class

P: n/a
Hello,
I have following (probably very basic) problem:
I made a html-frameset in VS.net, where the frames
itself are aspx-pages with webforms.
Now I want to access the webforms (eg. give a label a
text) from one .aspx.vb page.
I managed to get all the code into one file by writing
the same file in the codebehind statement of all aspx
files.
Now I have one big .aspx.vb file with:
Public Class Header
Public Class Main

There is a Label in the header.aspx and its defined
in header-class as
Public WithEvents HLabel As System.Web.UI.WebControls.Label

How do I access this Label from my Main Class? It has to
be possible, but I failed.

I tried this, but it didn't work:
Dim theHeader As Header = New Header()
theHeader.HLabel.Text = "Hello World"

This (and any try with "new") gives me the error:
"System.NullReferenceException: Object reference not set
to an instance of an object."

Any help is appreciated

Thanks in advance,
Salek
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In order to access a member of a non-shared class, you must obtain a
reference to an instance of that class. You have a couple of problems to
deal with here, and what sounds to me like a misconception that needs to be
straightened out. ASP.Net Pages have 2 components which never meet, but only
send messages back and forth to each other: The client-side HTML and the
server-side Class. They only SEEM to be connected. Now, you're dealing with
a frameset here, but you need to understand that the server-side elements of
these pages will never be able to see each other, as they exist for a brief
time at different times on the server, each while a request for that Page is
being processed. On the client, the 2 pages (client-side HTML) exist in the
same frameset, and for a much longer time (basically, while both pages are
loaded in the frameset, and neither one is being posted back to the server).
The only way to have these pages communicate is on the client-side, via
JavaScript. So, you will need to use JavaScript to access the HTML objects
in one page from the other page.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.

"Salek Talangi" <bl***@gmx.net> wrote in message
news:07****************************@phx.gbl...
Hello,
I have following (probably very basic) problem:
I made a html-frameset in VS.net, where the frames
itself are aspx-pages with webforms.
Now I want to access the webforms (eg. give a label a
text) from one .aspx.vb page.
I managed to get all the code into one file by writing
the same file in the codebehind statement of all aspx
files.
Now I have one big .aspx.vb file with:
Public Class Header
Public Class Main

There is a Label in the header.aspx and its defined
in header-class as
Public WithEvents HLabel As System.Web.UI.WebControls.Label

How do I access this Label from my Main Class? It has to
be possible, but I failed.

I tried this, but it didn't work:
Dim theHeader As Header = New Header()
theHeader.HLabel.Text = "Hello World"

This (and any try with "new") gives me the error:
"System.NullReferenceException: Object reference not set
to an instance of an object."

Any help is appreciated

Thanks in advance,
Salek

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.