Accessing variables of another class

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Accessing variables of another class

    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


    Salek Talangi Guest

  2. Similar Questions and Discussions

    1. #25377 [Bgs]: Class variables can be added out of class definition
      ID: 25377 Updated by: helly@php.net Reported By: forseti at oak dot rpg dot pl Status: Bogus Bug Type: ...
    2. Instance- and class-variables (was mixing in class methods)
      Hi -- On Thu, 2 Oct 2003, Mark J. Reed wrote: Also, every object should have the right to maintain state in instance variables that are...
    3. Instance- and class-variables (was mixing in class methods)
      Hi -- On Fri, 3 Oct 2003 dblack@superlink.net wrote: And of course the fact that it might actually be self.class.class_eval { @var } also...
    4. Instance- and class-variables (was mixing in class methods)
      Hi -- On Thu, 2 Oct 2003, Gavin Sinclair wrote: Ummm, what array? :-) I think you'd need something like: class Project class << self...
    5. Accessing page request / server variables in a class file.
      Hi, Here's a question for you all. Under "classic" ASP any ASP page could have any number of #Include files. Using #Include files I could have...
  3. #2

    Default Re: Accessing variables of another class

    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
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of little things.

    "Salek Talangi" <blama@gmx.net> wrote in message
    news:071601c35509$5b111a60$a401280a@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
    >
    >

    Kevin Spencer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139