473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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.
Jun 27 '08 #1
11 1654
Using @reference directive
(http://msdn2.microsoft.com/en-us/lib...5a(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" <in**@websearchstore.comwrote in message
news:u4****************@TK2MSFTNGP02.phx.gbl...
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.


Jun 27 '08 #2
Thanks a lot.

I'll read it.

Scott
"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
Using @reference directive
(http://msdn2.microsoft.com/en-us/lib...5a(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" <in**@websearchstore.comwrote in message
news:u4****************@TK2MSFTNGP02.phx.gbl...
>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.



Jun 27 '08 #3
On 21 Apr, 20:21, "Web Search Store" <i...@websearchstore.comwrote:
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 referto
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
Jun 27 '08 #4
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" <go****@philphall.me.ukwrote in message
news:b0**********************************@a70g2000 hsh.googlegroups.com...
On 21 Apr, 20:21, "Web Search Store" <i...@websearchstore.comwrote:
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
Jun 27 '08 #5
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" <go****@philphall.me.ukwrote in message
news:b0**********************************@a70g2000 hsh.googlegroups.com...
On 21 Apr, 20:21, "Web Search Store" <i...@websearchstore.comwrote:
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
Jun 27 '08 #6
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" <in**@websearchstore.comwrote in message news:uF**************@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" <go****@philphall.me.ukwrote in message
news:b0**********************************@a70g2000 hsh.googlegroups.com...
On 21 Apr, 20:21, "Web Search Store" <i...@websearchstore.comwrote:
>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

Jun 27 '08 #7
On 22 Apr, 21:03, "Web Search Store" <i...@websearchstore.comwrote:
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 createdit
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
Jun 27 '08 #8
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.)
Jun 27 '08 #9
Thanks.

I'll try what you have said.

Scott
"Stan" <go****@philphall.me.ukwrote in message
news:67**********************************@l42g2000 hsc.googlegroups.com...
On 22 Apr, 21:03, "Web Search Store" <i...@websearchstore.comwrote:
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
Jun 27 '08 #10
Thanks for this tip.

Scott
"Stan" <go****@philphall.me.ukwrote in message
news:f1**********************************@f63g2000 hsf.googlegroups.com...
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.)

Jun 27 '08 #11
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" <go****@philphall.me.ukwrote in message
news:67**********************************@l42g2000 hsc.googlegroups.com...
On 22 Apr, 21:03, "Web Search Store" <i...@websearchstore.comwrote:
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
Jun 27 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
2
by: Paul | last post by:
Hi, Is it true that I can only access a user controls public properties if I dynamically load it?, i.e. I cannot access a user controls public properties if I simply register the user control on...
6
by: darrel | last post by:
I'm still not quite sure how best to handle the passing of data between controls. This is a method I'm using at the moment: I have an XML file that contains a variety of page-centric...
3
by: Mick | last post by:
Hi, Dragging & Dropping my ascx control in my aspx page, I just wanna know how I can access its properties when validating the form ? The control is composed of 4 controls (2 txtbox and 2 dropdown...
6
by: Paperback Writer | last post by:
I have 30 textBox in my UserControl...they are with PROTECTED modifier. But i need to access these TextBox throught my WebForm... What is the best way to access them ? leaving PROTECTED and...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
7
by: Mark Chimes | last post by:
Hi All, I have multiple copies of the same form open in an app. (These are not MDI child forms). I then open a summary form that displays data from each of the previously open forms. I have a...
2
by: Rob | last post by:
I am not sure if this can be implemented.... There exists a TabContol (added at design time) to a form.. Tabs for this TabContol get added at run time. Usage of the following 2 properties...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.