473,394 Members | 2,002 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,394 software developers and data experts.

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="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" 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.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"/>


</body>

</html>

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

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

<%@ 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

m_addressesstring = 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.EventArgs)
Handles Me.Load

My_topdcl.topdcl1()

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
Jun 27 '08 #1
2 1692
On Apr 18, 12:01*pm, "Web Search Store" <i...@websearchstore.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="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" 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.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"/>

</body>

</html>

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

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

<%@ 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

m_addressesstring = 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.EventArgs)
Handles Me.Load

*My_topdcl.topdcl1()

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(addressesstring)" to
"Response.Write(My_topdcl.addressesstring)"

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

Happy coding!
Jun 27 '08 #2
Thanks a lot!

Scott
"Norm" <ne*****@gmail.comwrote in message
news:ae**********************************@n14g2000 pri.googlegroups.com...
On Apr 18, 12:01 pm, "Web Search Store" <i...@websearchstore.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="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" 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.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"/>

</body>

</html>

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

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

<%@ 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

m_addressesstring = 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.EventArgs)
Handles Me.Load

My_topdcl.topdcl1()

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(addressesstring)" to
"Response.Write(My_topdcl.addressesstring)"

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

Happy coding!
Jun 27 '08 #3

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

Similar topics

2
by: Jose Meireles | last post by:
Hi everyone, I'm trying to use public variables in a web form to hld specific values. What happens is that the public variables (declared as public x as y in the beginning of the class), doesn't...
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: Mrs. Conni Drejer | last post by:
Please help anyone: I have made a DLL (for DBCommunication) in which I have defined some public static variables/fields in a public class. This because I want these variables to be shared in all...
4
by: Webster | last post by:
Hello, Just wondering what's better programming style; to use public variables in a class or to use private/protected variables and then expose them via properties? For example:...
4
by: Nick Dreyer | last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA? I have successfully created the (Visual Basic 2003 .NET) COM and referenced it in an Excel 97 VBA project. The VBA...
27
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
7
by: Steve Mauldin | last post by:
I have a public variable that is declared in a public module. This Variable is stored into a Session variable and used to pass data from page to page. I am seeing on my local development box that...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
5
by: Web Search Store | last post by:
Hello, I made a web page using visual studio. I also made a public class in the app_code folder called 'allvars' In the main web page durning the page startup, I can refer to public shared...
3
by: PhilippeM | last post by:
Hi everyone! I have defined 3 public variables: Public OldCompany As Variant Public OldLast As Variant Public OldFirst As Variant A procedure defines those variables: OldCompany = !Company...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.