public variables in asp.net?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Web Search Store

    public variables in asp.net?

    I am trying to make variables available in my web application by making
    user controls

    I classic asp I was able to put them all in an #include which made them
    available throughout the asp script

    So here's my example, 2 .ascx files, and I want to use a variable, like a
    public variable, in the 2nd one (in the page load event)

    Even though I make a public property in the first topdcl_try.ascx file, it
    doesn't recognize it in the page load event.

    Here is the page:

    <%@ Page Language="VB" AutoEventWireup ="false" CodeFile="Defau lt.aspx.vb"
    Inherits="_Defa ult" %>

    <%@ Register TagPrefix="Util s" TagName="topdcl " Src="utils/topdcl_try.ascx "
    %>



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitl ed Page</title>

    </head>

    <body>


    <form id="form1" runat="server">

    <div>


    </div>

    </form>



    <Utils:topdcl id="My_topdcl" runat="server"/>




    </body>

    </html>

    ---------------------------------------------

    Here is the topdcl_try.ascx file:
    ------------------------------------------

    <%@ Control ClassName="topd cl" %>

    <script language="vb" runat="server">


    Private m_addressesstri ng as String= "adr,phone,zip, "

    Public Property addressesstring as String

    Get

    Return m_addressesstri ng

    End Get

    Set

    m_addressesstri ng = Value

    End Set

    End Property


    Public Sub topdcl1()


    addressesstring = "adr,phone,zip, "


    End Sub

    </script>

    ..--------------------------------------
    Here is the page load event:

    ---------------------------------------



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
    Handles Me.Load

    My_topdcl.topdc l1()

    Response.Write( addressesstring )

    'My_w.w1()

    End Sub



    I get an error saying the addressstring variable is not declared. I was
    hoping making a public property would make it available within the page, but
    it doesn't.I guess I don't understand how these properties work.



    As I said, in classic .asp I could put all the 'dim' statements at the top
    in an include, and the whole asp page could access them.



    Thanks for any help!



    Scott Baxter


  • Norm

    #2
    Re: public variables in asp.net?

    On Apr 18, 12:01 pm, "Web Search Store" <i...@websearch store.com>
    wrote:
     I am trying to make variables available in my web application by making
    user controls
    >
    I classic asp I was able to put them all in an #include which made them
    available throughout the asp script
    >
    So here's my example, 2 .ascx files, and I want to use a variable, like a
    public variable, in the 2nd one (in the page load event)
    >
    Even though I make a public property in the first topdcl_try.ascx file,  it
    doesn't recognize it in the page load event.
    >
    Here is the page:
    >
    <%@ Page Language="VB" AutoEventWireup ="false" CodeFile="Defau lt.aspx.vb"
    Inherits="_Defa ult" %>
    >
    <%@ Register TagPrefix="Util s" TagName="topdcl " Src="utils/topdcl_try.ascx "
    %>
    >
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    >
    <html xmlns="http://www.w3.org/1999/xhtml" >
    >
    <head runat="server">
    >
    <title>Untitl ed Page</title>
    >
    </head>
    >
    <body>
    >
    <form id="form1" runat="server">
    >
    <div>
    >
    </div>
    >
    </form>
    >
    <Utils:topdcl id="My_topdcl" runat="server"/>
    >
    </body>
    >
    </html>
    >
    ---------------------------------------------
    >
    Here is the topdcl_try.ascx file:
    ------------------------------------------
    >
    <%@ Control ClassName="topd cl" %>
    >
    <script language="vb" runat="server">
    >
    Private m_addressesstri ng as String= "adr,phone,zip, "
    >
    Public Property addressesstring as String
    >
    Get
    >
    Return m_addressesstri ng
    >
    End Get
    >
    Set
    >
    m_addressesstri ng = Value
    >
    End Set
    >
    End Property
    >
    Public Sub topdcl1()
    >
    addressesstring = "adr,phone,zip, "
    >
    End Sub
    >
    </script>
    >
    .--------------------------------------
    Here is the page load event:
    >
    ---------------------------------------
    >
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
    Handles Me.Load
    >
     My_topdcl.topdc l1()
    >
    Response.Write( addressesstring )
    >
    'My_w.w1()
    >
    End Sub
    >
    I get an error saying the addressstring variable is not declared. I was
    hoping making a public property would make it available within the page, but
    it doesn't.I guess I don't understand how these properties work.
    >
    As I said, in classic .asp I could put all the 'dim' statements at the top
    in an include, and the whole asp page could access them.
    >
    Thanks for any help!
    >
    Scott Baxter
    You need to reference the user control when accessing its public
    property:

    Change "Response.Write (addressesstrin g)" to
    "Response.Write (My_topdcl.addr essesstring)"

    The error was telling you exactly what was happening. There was no
    "addressstr ing" variable/property in scope.

    Happy coding!

    Comment

    • Web Search Store

      #3
      Re: public variables in asp.net?

      Thanks a lot!

      Scott
      "Norm" <neonorm@gmail. comwrote in message
      news:ae0ed727-924b-4e39-85e9-5582eaf58a30@n1 4g2000pri.googl egroups.com...
      On Apr 18, 12:01 pm, "Web Search Store" <i...@websearch store.com>
      wrote:
      I am trying to make variables available in my web application by making
      user controls
      >
      I classic asp I was able to put them all in an #include which made them
      available throughout the asp script
      >
      So here's my example, 2 .ascx files, and I want to use a variable, like a
      public variable, in the 2nd one (in the page load event)
      >
      Even though I make a public property in the first topdcl_try.ascx file, it
      doesn't recognize it in the page load event.
      >
      Here is the page:
      >
      <%@ Page Language="VB" AutoEventWireup ="false" CodeFile="Defau lt.aspx.vb"
      Inherits="_Defa ult" %>
      >
      <%@ Register TagPrefix="Util s" TagName="topdcl "
      Src="utils/topdcl_try.ascx "
      %>
      >
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      >
      <html xmlns="http://www.w3.org/1999/xhtml" >
      >
      <head runat="server">
      >
      <title>Untitl ed Page</title>
      >
      </head>
      >
      <body>
      >
      <form id="form1" runat="server">
      >
      <div>
      >
      </div>
      >
      </form>
      >
      <Utils:topdcl id="My_topdcl" runat="server"/>
      >
      </body>
      >
      </html>
      >
      ---------------------------------------------
      >
      Here is the topdcl_try.ascx file:
      ------------------------------------------
      >
      <%@ Control ClassName="topd cl" %>
      >
      <script language="vb" runat="server">
      >
      Private m_addressesstri ng as String= "adr,phone,zip, "
      >
      Public Property addressesstring as String
      >
      Get
      >
      Return m_addressesstri ng
      >
      End Get
      >
      Set
      >
      m_addressesstri ng = Value
      >
      End Set
      >
      End Property
      >
      Public Sub topdcl1()
      >
      addressesstring = "adr,phone,zip, "
      >
      End Sub
      >
      </script>
      >
      .--------------------------------------
      Here is the page load event:
      >
      ---------------------------------------
      >
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As
      System.EventArg s)
      Handles Me.Load
      >
      My_topdcl.topdc l1()
      >
      Response.Write( addressesstring )
      >
      'My_w.w1()
      >
      End Sub
      >
      I get an error saying the addressstring variable is not declared. I was
      hoping making a public property would make it available within the page,
      but
      it doesn't.I guess I don't understand how these properties work.
      >
      As I said, in classic .asp I could put all the 'dim' statements at the top
      in an include, and the whole asp page could access them.
      >
      Thanks for any help!
      >
      Scott Baxter
      You need to reference the user control when accessing its public
      property:

      Change "Response.Write (addressesstrin g)" to
      "Response.Write (My_topdcl.addr essesstring)"

      The error was telling you exactly what was happening. There was no
      "addressstr ing" variable/property in scope.

      Happy coding!


      Comment

      Working...