Make sure you use inline code for that example, whether C# or VB.NET.
Juan T. Llibre, asp.net MVP
"Web Search Store" <info@websearchstore.com> wrote in message news:uFqYsPLpIHA.1952@TK2MSFTNGP05.phx.gbl...
> 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" <google@philphall.me.uk> wrote in message
> news:b03d68d7-8626-4dd5-8c5e-b706814d8386@a70g2000hsh.googlegroups.com...
> On 21 Apr, 20:21, "Web Search Store" <i...@websearchstore.com> 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
>