Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

public variables in asp.net?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Web Search Store - 18 Apr 2008 20:01 GMT
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
Norm - 18 Apr 2008 20:55 GMT
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
[quoted text clipped - 104 lines]
>
> 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!
Web Search Store - 18 Apr 2008 22:24 GMT
Thanks a lot!

Scott
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
[quoted text clipped - 107 lines]
>
> 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!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.