is there a way to refer to public properties in other user controls

Discussion in 'ASP .Net' started by Web Search Store, Apr 21, 2008.

  1. Hello,

    I set up a web page with 2 user controls.

    In classic asp, the first one did all the declarations, and the second one
    used the values, and could reset it.

    In ASP.Net so far I can't see how to relate them so this will work.

    This user control defines the properties:



    <%@ Control ClassName="topdcl" %>

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


    Private m_addressesstring as String= "adr,phone,zip,"

    Public Property addressesstring() As String


    Get

    Return m_addressesstring

    End Get

    Set(ByVal value As String)

    m_addressesstring = Value

    End Set

    End Property


    Public Sub topdcl1()


    addressesstring= "adr,phone,zip,"


    End Sub

    </script>





    This user control tries to access the public property 'addressstring', but
    can't:



    <%@ Control ClassName="w" %>

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

    Public Sub w1()


    my_topdcl.addressesstring = addressesstring & ",zip"


    End Sub

    </script>



    Here's the page that calls them:



    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    Inherits="_Default" %>

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

    <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>




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

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

    <head runat="server">

    <title>Untitled Page</title>

    </head>

    <body>


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

    <div>


    </div>

    </form>



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

    <Utils:w id="My_w" runat="server"/>


    </body>

    </html>



    Here's the code behind for this page:



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

    My_topdcl.topdcl1()

    My_w.w1()


    End Sub

    I would really appreciate any help.

    At this point, my only working solution seems to be to combine all the code
    into 1 usercontrol, instead of having several. Then variables can refer to
    variables in their own class with no problem.



    In classic asp, I used includes with all the 'dim' statements in the first,
    and the subroutines in later includes.



    Thanks.



    Scott Baxter.
     
    Web Search Store, Apr 21, 2008
    #1
    1. Advertising

  2. Web Search Store

    Teemu Keiski Guest

    Using @reference directive
    (http://msdn2.microsoft.com/en-us/library/w70c655a(VS.80).aspx) makes the
    UCs type accessible, although not 100% sure how it would behave in this
    situation as they'd (UCs) need to reference each other but you can try.

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Web Search Store" <> wrote in message
    news:u4GDlT%...
    > Hello,
    >
    > I set up a web page with 2 user controls.
    >
    > In classic asp, the first one did all the declarations, and the second one
    > used the values, and could reset it.
    >
    > In ASP.Net so far I can't see how to relate them so this will work.
    >
    > This user control defines the properties:
    >
    >
    >
    > <%@ Control ClassName="topdcl" %>
    >
    > <script language="vb" runat="server">
    >
    >
    > Private m_addressesstring as String= "adr,phone,zip,"
    >
    > Public Property addressesstring() As String
    >
    >
    > Get
    >
    > Return m_addressesstring
    >
    > End Get
    >
    > Set(ByVal value As String)
    >
    > m_addressesstring = Value
    >
    > End Set
    >
    > End Property
    >
    >
    > Public Sub topdcl1()
    >
    >
    > addressesstring= "adr,phone,zip,"
    >
    >
    > End Sub
    >
    > </script>
    >
    >
    >
    >
    >
    > This user control tries to access the public property 'addressstring', but
    > can't:
    >
    >
    >
    > <%@ Control ClassName="w" %>
    >
    > <script language="vb" runat="server">
    >
    > Public Sub w1()
    >
    >
    > my_topdcl.addressesstring = addressesstring & ",zip"
    >
    >
    > End Sub
    >
    > </script>
    >
    >
    >
    > Here's the page that calls them:
    >
    >
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    > Inherits="_Default" %>
    >
    > <%@ Register TagPrefix="Utils" TagName="topdcl"
    > Src="utils/topdcl_try.ascx" %>
    >
    > <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>
    >
    >
    >
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    >
    > <head runat="server">
    >
    > <title>Untitled Page</title>
    >
    > </head>
    >
    > <body>
    >
    >
    > <form id="form1" runat="server">
    >
    > <div>
    >
    >
    > </div>
    >
    > </form>
    >
    >
    >
    > <Utils:topdcl id="My_topdcl" runat="server"/>
    >
    > <Utils:w id="My_w" runat="server"/>
    >
    >
    > </body>
    >
    > </html>
    >
    >
    >
    > Here's the code behind for this page:
    >
    >
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >
    > My_topdcl.topdcl1()
    >
    > My_w.w1()
    >
    >
    > End Sub
    >
    > I would really appreciate any help.
    >
    > At this point, my only working solution seems to be to combine all the
    > code into 1 usercontrol, instead of having several. Then variables can
    > refer to variables in their own class with no problem.
    >
    >
    >
    > In classic asp, I used includes with all the 'dim' statements in the
    > first, and the subroutines in later includes.
    >
    >
    >
    > Thanks.
    >
    >
    >
    > Scott Baxter.
    >
    >
     
    Teemu Keiski, Apr 21, 2008
    #2
    1. Advertising

  3. Thanks a lot.

    I'll read it.

    Scott
    "Teemu Keiski" <> wrote in message
    news:%23SQMCx%...
    > Using @reference directive
    > (http://msdn2.microsoft.com/en-us/library/w70c655a(VS.80).aspx) makes the
    > UCs type accessible, although not 100% sure how it would behave in this
    > situation as they'd (UCs) need to reference each other but you can try.
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    > "Web Search Store" <> wrote in message
    > news:u4GDlT%...
    >> Hello,
    >>
    >> I set up a web page with 2 user controls.
    >>
    >> In classic asp, the first one did all the declarations, and the second
    >> one used the values, and could reset it.
    >>
    >> In ASP.Net so far I can't see how to relate them so this will work.
    >>
    >> This user control defines the properties:
    >>
    >>
    >>
    >> <%@ Control ClassName="topdcl" %>
    >>
    >> <script language="vb" runat="server">
    >>
    >>
    >> Private m_addressesstring as String= "adr,phone,zip,"
    >>
    >> Public Property addressesstring() As String
    >>
    >>
    >> Get
    >>
    >> Return m_addressesstring
    >>
    >> End Get
    >>
    >> Set(ByVal value As String)
    >>
    >> m_addressesstring = Value
    >>
    >> End Set
    >>
    >> End Property
    >>
    >>
    >> Public Sub topdcl1()
    >>
    >>
    >> addressesstring= "adr,phone,zip,"
    >>
    >>
    >> End Sub
    >>
    >> </script>
    >>
    >>
    >>
    >>
    >>
    >> This user control tries to access the public property 'addressstring',
    >> but can't:
    >>
    >>
    >>
    >> <%@ Control ClassName="w" %>
    >>
    >> <script language="vb" runat="server">
    >>
    >> Public Sub w1()
    >>
    >>
    >> my_topdcl.addressesstring = addressesstring & ",zip"
    >>
    >>
    >> End Sub
    >>
    >> </script>
    >>
    >>
    >>
    >> Here's the page that calls them:
    >>
    >>
    >>
    >> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    >> Inherits="_Default" %>
    >>
    >> <%@ Register TagPrefix="Utils" TagName="topdcl"
    >> Src="utils/topdcl_try.ascx" %>
    >>
    >> <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>
    >>
    >>
    >>
    >>
    >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >>
    >> <html xmlns="http://www.w3.org/1999/xhtml" >
    >>
    >> <head runat="server">
    >>
    >> <title>Untitled Page</title>
    >>
    >> </head>
    >>
    >> <body>
    >>
    >>
    >> <form id="form1" runat="server">
    >>
    >> <div>
    >>
    >>
    >> </div>
    >>
    >> </form>
    >>
    >>
    >>
    >> <Utils:topdcl id="My_topdcl" runat="server"/>
    >>
    >> <Utils:w id="My_w" runat="server"/>
    >>
    >>
    >> </body>
    >>
    >> </html>
    >>
    >>
    >>
    >> Here's the code behind for this page:
    >>
    >>
    >>
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >>
    >> My_topdcl.topdcl1()
    >>
    >> My_w.w1()
    >>
    >>
    >> End Sub
    >>
    >> I would really appreciate any help.
    >>
    >> At this point, my only working solution seems to be to combine all the
    >> code into 1 usercontrol, instead of having several. Then variables can
    >> refer to variables in their own class with no problem.
    >>
    >>
    >>
    >> In classic asp, I used includes with all the 'dim' statements in the
    >> first, and the subroutines in later includes.
    >>
    >>
    >>
    >> Thanks.
    >>
    >>
    >>
    >> Scott Baxter.
    >>
    >>

    >
    >
     
    Web Search Store, Apr 21, 2008
    #3
  4. Web Search Store

    Stan Guest

    Re: is there a way to refer to public properties in other usercontrols

    On 21 Apr, 20:21, "Web Search Store" <> wrote:
    > Hello,
    >
    > I set up a web page with 2 user controls.
    >
    > In classic asp, the first one did all the declarations, and the second one
    > used the values, and could reset it.
    >
    > In ASP.Net so far I can't see how to relate them so this will work.
    >
    > This user control defines the properties:
    >
    > <%@ Control ClassName="topdcl" %>
    >
    > <script language="vb" runat="server">
    >
    > Private m_addressesstring as String= "adr,phone,zip,"
    >
    > Public Property addressesstring() As String
    >
    > Get
    >
    > Return m_addressesstring
    >
    > End Get
    >
    > Set(ByVal value As String)
    >
    > m_addressesstring = Value
    >
    > End Set
    >
    > End Property
    >
    > Public Sub topdcl1()
    >
    > addressesstring= "adr,phone,zip,"
    >
    > End Sub
    >
    > </script>
    >
    > This user control tries to access the public property 'addressstring', but
    > can't:
    >
    > <%@ Control ClassName="w" %>
    >
    > <script language="vb" runat="server">
    >
    > Public Sub w1()
    >
    > my_topdcl.addressesstring = addressesstring & ",zip"
    >
    > End Sub
    >
    > </script>
    >
    > Here's the page that calls them:
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    > Inherits="_Default" %>
    >
    > <%@ Register TagPrefix="Utils" TagName="topdcl" Src="utils/topdcl_try.ascx"
    > %>
    >
    > <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    >
    > <head runat="server">
    >
    > <title>Untitled Page</title>
    >
    > </head>
    >
    > <body>
    >
    > <form id="form1" runat="server">
    >
    > <div>
    >
    > </div>
    >
    > </form>
    >
    > <Utils:topdcl id="My_topdcl" runat="server"/>
    >
    > <Utils:w id="My_w" runat="server"/>
    >
    > </body>
    >
    > </html>
    >
    > Here's the code behind for this page:
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    > Handles Me.Load
    >
    > My_topdcl.topdcl1()
    >
    > My_w.w1()
    >
    >  End Sub
    >
    >  I would really appreciate any help.
    >
    > At this point, my only working solution seems to be to combine all the code
    > into 1 usercontrol, instead of having several.  Then variables can refer to
    > variables in their own class with no problem.
    >
    > In classic asp, I used includes with all the 'dim' statements in the first,
    > and the subroutines in later includes.
    >
    > Thanks.
    >
    > Scott Baxter.


    Dear Scott

    Forget classic asp

    ASP.NET is an entirely different platform. It is not merely an
    extension of ASP and inherits practically nothing from it. VB.NET is
    not the same as the VB used in ASP.

    If you want re-usable code or global variables that are not integral
    to any visual controls then create them in a separate .vb code file
    and store it in the APP_CODE folder of the web site. Any namespaces or
    classes created there will be within scope of all pages without the
    need for include directives.

    User controls are for re-usable visual controls and layouts. They are
    not designed to act as an application-wide repository for code.
    Anything contained within them that is publicly scoped is accessible
    only from a host page that contains an instance of it. For example if
    a page has an instance of topdcl placed on it (there can be as many of
    them as you like) it will have a unique identifier e.g. topdcl1 The
    property named "addressesstring" then becomes topdcl1.addressstring.
    It will not be accessible from any other user control either within
    the same or a different page, furthermore the value is only relevent
    to that particular instance of topdcl.

    HTH
     
    Stan, Apr 22, 2008
    #4
  5. Thank you for that insight.

    I'll try putting a class in the app_code folder and see if I can get what I
    want.

    I'm fully aware that classic .asp is a totally different story. I'm just
    trying to accomplish what I used to be able to do there.

    Anyway. I'll give it a try.

    Thanks.

    Scott
    "Stan" <> wrote in message
    news:...
    On 21 Apr, 20:21, "Web Search Store" <> wrote:
    > Hello,
    >
    > I set up a web page with 2 user controls.
    >
    > In classic asp, the first one did all the declarations, and the second one
    > used the values, and could reset it.
    >
    > In ASP.Net so far I can't see how to relate them so this will work.
    >
    > This user control defines the properties:
    >
    > <%@ Control ClassName="topdcl" %>
    >
    > <script language="vb" runat="server">
    >
    > Private m_addressesstring as String= "adr,phone,zip,"
    >
    > Public Property addressesstring() As String
    >
    > Get
    >
    > Return m_addressesstring
    >
    > End Get
    >
    > Set(ByVal value As String)
    >
    > m_addressesstring = Value
    >
    > End Set
    >
    > End Property
    >
    > Public Sub topdcl1()
    >
    > addressesstring= "adr,phone,zip,"
    >
    > End Sub
    >
    > </script>
    >
    > This user control tries to access the public property 'addressstring', but
    > can't:
    >
    > <%@ Control ClassName="w" %>
    >
    > <script language="vb" runat="server">
    >
    > Public Sub w1()
    >
    > my_topdcl.addressesstring = addressesstring & ",zip"
    >
    > End Sub
    >
    > </script>
    >
    > Here's the page that calls them:
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    > Inherits="_Default" %>
    >
    > <%@ Register TagPrefix="Utils" TagName="topdcl"
    > Src="utils/topdcl_try.ascx"
    > %>
    >
    > <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    >
    > <head runat="server">
    >
    > <title>Untitled Page</title>
    >
    > </head>
    >
    > <body>
    >
    > <form id="form1" runat="server">
    >
    > <div>
    >
    > </div>
    >
    > </form>
    >
    > <Utils:topdcl id="My_topdcl" runat="server"/>
    >
    > <Utils:w id="My_w" runat="server"/>
    >
    > </body>
    >
    > </html>
    >
    > Here's the code behind for this page:
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs)
    > Handles Me.Load
    >
    > My_topdcl.topdcl1()
    >
    > My_w.w1()
    >
    > End Sub
    >
    > I would really appreciate any help.
    >
    > At this point, my only working solution seems to be to combine all the
    > code
    > into 1 usercontrol, instead of having several. Then variables can refer to
    > variables in their own class with no problem.
    >
    > In classic asp, I used includes with all the 'dim' statements in the
    > first,
    > and the subroutines in later includes.
    >
    > Thanks.
    >
    > Scott Baxter.


    Dear Scott

    Forget classic asp

    ASP.NET is an entirely different platform. It is not merely an
    extension of ASP and inherits practically nothing from it. VB.NET is
    not the same as the VB used in ASP.

    If you want re-usable code or global variables that are not integral
    to any visual controls then create them in a separate .vb code file
    and store it in the APP_CODE folder of the web site. Any namespaces or
    classes created there will be within scope of all pages without the
    need for include directives.

    User controls are for re-usable visual controls and layouts. They are
    not designed to act as an application-wide repository for code.
    Anything contained within them that is publicly scoped is accessible
    only from a host page that contains an instance of it. For example if
    a page has an instance of topdcl placed on it (there can be as many of
    them as you like) it will have a unique identifier e.g. topdcl1 The
    property named "addressesstring" then becomes topdcl1.addressstring.
    It will not be accessible from any other user control either within
    the same or a different page, furthermore the value is only relevent
    to that particular instance of topdcl.

    HTH
     
    Web Search Store, Apr 22, 2008
    #5
  6. Hello,

    Sorry to be so dense. I have been reading about the App_code folder and
    trying to put a class in there with a global variable.

    Here's what I have:

    in a file globals.vb:

    Partial Class allofthem

    Public ccc As String = "howdy"

    End Class



    Then, I rightclicked the project, and added existing item, and added this
    file, which is in the app_code folder. But the project doesn't seem to know
    about it.

    What do I do next? My project didn't have an app_code folder, I created it
    manually.



    Do I need to put an 'inherit' or import statement in?



    any help would be appreciated.

    scott





    "Stan" <> wrote in message
    news:...
    On 21 Apr, 20:21, "Web Search Store" <> wrote:
    > Hello,
    >
    > I set up a web page with 2 user controls.
    >
    > In classic asp, the first one did all the declarations, and the second one
    > used the values, and could reset it.
    >
    > In ASP.Net so far I can't see how to relate them so this will work.
    >
    > This user control defines the properties:
    >
    > <%@ Control ClassName="topdcl" %>
    >
    > <script language="vb" runat="server">
    >
    > Private m_addressesstring as String= "adr,phone,zip,"
    >
    > Public Property addressesstring() As String
    >
    > Get
    >
    > Return m_addressesstring
    >
    > End Get
    >
    > Set(ByVal value As String)
    >
    > m_addressesstring = Value
    >
    > End Set
    >
    > End Property
    >
    > Public Sub topdcl1()
    >
    > addressesstring= "adr,phone,zip,"
    >
    > End Sub
    >
    > </script>
    >
    > This user control tries to access the public property 'addressstring', but
    > can't:
    >
    > <%@ Control ClassName="w" %>
    >
    > <script language="vb" runat="server">
    >
    > Public Sub w1()
    >
    > my_topdcl.addressesstring = addressesstring & ",zip"
    >
    > End Sub
    >
    > </script>
    >
    > Here's the page that calls them:
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    > Inherits="_Default" %>
    >
    > <%@ Register TagPrefix="Utils" TagName="topdcl"
    > Src="utils/topdcl_try.ascx"
    > %>
    >
    > <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    >
    > <head runat="server">
    >
    > <title>Untitled Page</title>
    >
    > </head>
    >
    > <body>
    >
    > <form id="form1" runat="server">
    >
    > <div>
    >
    > </div>
    >
    > </form>
    >
    > <Utils:topdcl id="My_topdcl" runat="server"/>
    >
    > <Utils:w id="My_w" runat="server"/>
    >
    > </body>
    >
    > </html>
    >
    > Here's the code behind for this page:
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs)
    > Handles Me.Load
    >
    > My_topdcl.topdcl1()
    >
    > My_w.w1()
    >
    > End Sub
    >
    > I would really appreciate any help.
    >
    > At this point, my only working solution seems to be to combine all the
    > code
    > into 1 usercontrol, instead of having several. Then variables can refer to
    > variables in their own class with no problem.
    >
    > In classic asp, I used includes with all the 'dim' statements in the
    > first,
    > and the subroutines in later includes.
    >
    > Thanks.
    >
    > Scott Baxter.


    Dear Scott

    Forget classic asp

    ASP.NET is an entirely different platform. It is not merely an
    extension of ASP and inherits practically nothing from it. VB.NET is
    not the same as the VB used in ASP.

    If you want re-usable code or global variables that are not integral
    to any visual controls then create them in a separate .vb code file
    and store it in the APP_CODE folder of the web site. Any namespaces or
    classes created there will be within scope of all pages without the
    need for include directives.

    User controls are for re-usable visual controls and layouts. They are
    not designed to act as an application-wide repository for code.
    Anything contained within them that is publicly scoped is accessible
    only from a host page that contains an instance of it. For example if
    a page has an instance of topdcl placed on it (there can be as many of
    them as you like) it will have a unique identifier e.g. topdcl1 The
    property named "addressesstring" then becomes topdcl1.addressstring.
    It will not be accessible from any other user control either within
    the same or a different page, furthermore the value is only relevent
    to that particular instance of topdcl.

    HTH
     
    Web Search Store, Apr 22, 2008
    #6
  7. Please follow this walkthrough for using Properties in Class files:

    http://msdn2.microsoft.com/en-us/library/we4hy2z9.aspx

    You don't need to reference the Class file(s).

    Make sure you use inline code for that example, whether C# or VB.NET.
    There's special rules for using classes in code-behind.




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "Web Search Store" <> wrote in message news:...
    > Hello,
    >
    > Sorry to be so dense. I have been reading about the App_code folder and trying to put a class in there with a global
    > variable.
    >
    > Here's what I have:
    >
    > in a file globals.vb:
    >
    > Partial Class allofthem
    >
    > Public ccc As String = "howdy"
    >
    > End Class
    >
    >
    >
    > Then, I rightclicked the project, and added existing item, and added this file, which is in the app_code folder. But
    > the project doesn't seem to know about it.
    >
    > What do I do next? My project didn't have an app_code folder, I created it manually.
    >
    >
    >
    > Do I need to put an 'inherit' or import statement in?
    >
    >
    >
    > any help would be appreciated.
    >
    > scott
    >
    >
    >
    >
    >
    > "Stan" <> wrote in message
    > news:...
    > On 21 Apr, 20:21, "Web Search Store" <> wrote:
    >> Hello,
    >>
    >> I set up a web page with 2 user controls.
    >>
    >> In classic asp, the first one did all the declarations, and the second one
    >> used the values, and could reset it.
    >>
    >> In ASP.Net so far I can't see how to relate them so this will work.
    >>
    >> This user control defines the properties:
    >>
    >> <%@ Control ClassName="topdcl" %>
    >>
    >> <script language="vb" runat="server">
    >>
    >> Private m_addressesstring as String= "adr,phone,zip,"
    >>
    >> Public Property addressesstring() As String
    >>
    >> Get
    >>
    >> Return m_addressesstring
    >>
    >> End Get
    >>
    >> Set(ByVal value As String)
    >>
    >> m_addressesstring = Value
    >>
    >> End Set
    >>
    >> End Property
    >>
    >> Public Sub topdcl1()
    >>
    >> addressesstring= "adr,phone,zip,"
    >>
    >> End Sub
    >>
    >> </script>
    >>
    >> This user control tries to access the public property 'addressstring', but
    >> can't:
    >>
    >> <%@ Control ClassName="w" %>
    >>
    >> <script language="vb" runat="server">
    >>
    >> Public Sub w1()
    >>
    >> my_topdcl.addressesstring = addressesstring & ",zip"
    >>
    >> End Sub
    >>
    >> </script>
    >>
    >> Here's the page that calls them:
    >>
    >> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
    >> Inherits="_Default" %>
    >>
    >> <%@ Register TagPrefix="Utils" TagName="topdcl" Src="utils/topdcl_try.ascx"
    >> %>
    >>
    >> <%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>
    >>
    >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >>
    >> <html xmlns="http://www.w3.org/1999/xhtml" >
    >>
    >> <head runat="server">
    >>
    >> <title>Untitled Page</title>
    >>
    >> </head>
    >>
    >> <body>
    >>
    >> <form id="form1" runat="server">
    >>
    >> <div>
    >>
    >> </div>
    >>
    >> </form>
    >>
    >> <Utils:topdcl id="My_topdcl" runat="server"/>
    >>
    >> <Utils:w id="My_w" runat="server"/>
    >>
    >> </body>
    >>
    >> </html>
    >>
    >> Here's the code behind for this page:
    >>
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    >> Handles Me.Load
    >>
    >> My_topdcl.topdcl1()
    >>
    >> My_w.w1()
    >>
    >> End Sub
    >>
    >> I would really appreciate any help.
    >>
    >> At this point, my only working solution seems to be to combine all the code
    >> into 1 usercontrol, instead of having several. Then variables can refer to
    >> variables in their own class with no problem.
    >>
    >> In classic asp, I used includes with all the 'dim' statements in the first,
    >> and the subroutines in later includes.
    >>
    >> Thanks.
    >>
    >> Scott Baxter.

    >
    > Dear Scott
    >
    > Forget classic asp
    >
    > ASP.NET is an entirely different platform. It is not merely an
    > extension of ASP and inherits practically nothing from it. VB.NET is
    > not the same as the VB used in ASP.
    >
    > If you want re-usable code or global variables that are not integral
    > to any visual controls then create them in a separate .vb code file
    > and store it in the APP_CODE folder of the web site. Any namespaces or
    > classes created there will be within scope of all pages without the
    > need for include directives.
    >
    > User controls are for re-usable visual controls and layouts. They are
    > not designed to act as an application-wide repository for code.
    > Anything contained within them that is publicly scoped is accessible
    > only from a host page that contains an instance of it. For example if
    > a page has an instance of topdcl placed on it (there can be as many of
    > them as you like) it will have a unique identifier e.g. topdcl1 The
    > property named "addressesstring" then becomes topdcl1.addressstring.
    > It will not be accessible from any other user control either within
    > the same or a different page, furthermore the value is only relevent
    > to that particular instance of topdcl.
    >
    > HTH
    >
     
    Juan T. Llibre, Apr 23, 2008
    #7
  8. Web Search Store

    Stan Guest

    Re: is there a way to refer to public properties in other usercontrols

    On 22 Apr, 21:03, "Web Search Store" <> wrote:
    > Hello,
    >
    > Sorry to be so dense.  I have been reading about the App_code folder and
    > trying to put a class in there with a global variable.
    >
    > Here's what I have:
    >
    > in a file globals.vb:
    >
    > Partial Class allofthem
    >
    > Public ccc As String = "howdy"
    >
    > End Class
    >
    > Then, I rightclicked the project, and added existing item, and added this
    > file, which is in the app_code folder.  But the project doesn't seem to know
    > about it.
    >
    > What do I do next?  My project didn't have an app_code folder, I created it
    > manually.
    >
    > Do I need to put an 'inherit' or import statement in?
    >
    > any help would be appreciated.
    >
    > scott
    >


    Hi

    I've tried the same scenario as you and in the same manner but
    everything seems to work fine. (There is no need for any specific
    import or inherit statement)

    Just as a check. Did you create an ordinary web page and try some code
    along the following lines (in say the Page_Load event):

    Dim aot As New allofthem
    Response.Write(aot.ccc)

    BTW the App_Code folder can be added to the site by right-clicking the
    root of the site in Solution Explorer and choosing the option:

    "Add ASP.NET folder" --> App_Code

    One other tip. If you add the modifier "Shared" there is no need to
    create an instance of the class to access publicly scoped variables
    e.g.

    Public Shared AString = "some text"

    Then the content of Astring can be accesses in one line thus:

    Response.Write(allofthem.AString)

    Stan
     
    Stan, Apr 23, 2008
    #8
  9. Web Search Store

    Stan Guest

    Re: is there a way to refer to public properties in other usercontrols

    Hello again:

    I've just spotted the mistake.

    Your class declaration needs to have the "public" attribute as well
    thus:

    Public Class allofthem

    ....

    Stan

    (P.S. the attribute "Partial" is to allow Class code to be spread over
    more than one file.)
     
    Stan, Apr 23, 2008
    #9
  10. Thanks.

    I'll try what you have said.

    Scott
    "Stan" <> wrote in message
    news:...
    On 22 Apr, 21:03, "Web Search Store" <> wrote:
    > Hello,
    >
    > Sorry to be so dense. I have been reading about the App_code folder and
    > trying to put a class in there with a global variable.
    >
    > Here's what I have:
    >
    > in a file globals.vb:
    >
    > Partial Class allofthem
    >
    > Public ccc As String = "howdy"
    >
    > End Class
    >
    > Then, I rightclicked the project, and added existing item, and added this
    > file, which is in the app_code folder. But the project doesn't seem to
    > know
    > about it.
    >
    > What do I do next? My project didn't have an app_code folder, I created it
    > manually.
    >
    > Do I need to put an 'inherit' or import statement in?
    >
    > any help would be appreciated.
    >
    > scott
    >


    Hi

    I've tried the same scenario as you and in the same manner but
    everything seems to work fine. (There is no need for any specific
    import or inherit statement)

    Just as a check. Did you create an ordinary web page and try some code
    along the following lines (in say the Page_Load event):

    Dim aot As New allofthem
    Response.Write(aot.ccc)

    BTW the App_Code folder can be added to the site by right-clicking the
    root of the site in Solution Explorer and choosing the option:

    "Add ASP.NET folder" --> App_Code

    One other tip. If you add the modifier "Shared" there is no need to
    create an instance of the class to access publicly scoped variables
    e.g.

    Public Shared AString = "some text"

    Then the content of Astring can be accesses in one line thus:

    Response.Write(allofthem.AString)

    Stan
     
    Web Search Store, Apr 23, 2008
    #10
  11. Thanks for this tip.

    Scott
    "Stan" <> wrote in message
    news:...
    > Hello again:
    >
    > I've just spotted the mistake.
    >
    > Your class declaration needs to have the "public" attribute as well
    > thus:
    >
    > Public Class allofthem
    >
    > ...
    >
    > Stan
    >
    > (P.S. the attribute "Partial" is to allow Class code to be spread over
    > more than one file.)
     
    Web Search Store, Apr 23, 2008
    #11
  12. Hello,

    I think you finally hit on what I needed. Thanks a lot. I have some user
    controls that I want to refer to some public arrays, without having to
    instantiate a new version of them each time. This class:

    Imports Microsoft.VisualBasic

    Public Class Try2

    Public Shared ihope As String = "whoknows"

    End Class

    in the 'App_Code' folder seems to do what I need.



    I can refer to the variable ihope in the page_load like this:



    response.write (try2.ihope)



    Also, I can refer to it in my usercontrol like this:



    <%@ Control ClassName="w" %>

    helloooo

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

    Public Sub w1()

    Response.Write("again" & Try2.ihope)

    End Sub

    </script>

    I think this will accomplish what I want, without a lot of extra property
    declarations and all that.



    I will see.



    Thanks.



    Scott

    "Stan" <> wrote in message
    news:...
    On 22 Apr, 21:03, "Web Search Store" <> wrote:
    > Hello,
    >
    > Sorry to be so dense. I have been reading about the App_code folder and
    > trying to put a class in there with a global variable.
    >
    > Here's what I have:
    >
    > in a file globals.vb:
    >
    > Partial Class allofthem
    >
    > Public ccc As String = "howdy"
    >
    > End Class
    >
    > Then, I rightclicked the project, and added existing item, and added this
    > file, which is in the app_code folder. But the project doesn't seem to
    > know
    > about it.
    >
    > What do I do next? My project didn't have an app_code folder, I created it
    > manually.
    >
    > Do I need to put an 'inherit' or import statement in?
    >
    > any help would be appreciated.
    >
    > scott
    >


    Hi

    I've tried the same scenario as you and in the same manner but
    everything seems to work fine. (There is no need for any specific
    import or inherit statement)

    Just as a check. Did you create an ordinary web page and try some code
    along the following lines (in say the Page_Load event):

    Dim aot As New allofthem
    Response.Write(aot.ccc)

    BTW the App_Code folder can be added to the site by right-clicking the
    root of the site in Solution Explorer and choosing the option:

    "Add ASP.NET folder" --> App_Code

    One other tip. If you add the modifier "Shared" there is no need to
    create an instance of the class to access publicly scoped variables
    e.g.

    Public Shared AString = "some text"

    Then the content of Astring can be accesses in one line thus:

    Response.Write(allofthem.AString)

    Stan
     
    Web Search Store, Apr 23, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,381
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    590
    SpamProof
    Oct 21, 2003
  3. KJ
    Replies:
    0
    Views:
    125
  4. Web Search Store

    is there a way to refer to public properties in other user controls

    Web Search Store, Apr 21, 2008, in forum: ASP .Net Web Controls
    Replies:
    11
    Views:
    247
    Web Search Store
    Apr 23, 2008
  5. Web Search Store

    is there a way to refer to public properties in other user controls

    Web Search Store, Apr 21, 2008, in forum: ASP .Net Web Services
    Replies:
    11
    Views:
    251
    Web Search Store
    Apr 23, 2008
Loading...

Share This Page