public variables in asp.net?

public variables in asp.net?

am 18.04.2008 21:01:05 von Web Search Store

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



"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





Untitled Page


























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

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

<%@ Control ClassName="topdcl" %>



..--------------------------------------
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

Re: public variables in asp.net?

am 18.04.2008 21:55:13 von Norm

On Apr 18, 12:01=A0pm, "Web Search Store"
wrote:
> =A0I 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, =
=A0it
> doesn't recognize it in the page load event.
>
> Here is the page:
>
> <%@ Page Language=3D"VB" AutoEventWireup=3D"false" CodeFile=3D"Default.asp=
x.vb"
> Inherits=3D"_Default" %>
>
> <%@ Register TagPrefix=3D"Utils" TagName=3D"topdcl" Src=3D"utils/topdcl_tr=
y.ascx"
> %>
>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
>
>
>
>
> Untitled Page
>
>
>
>
>
>


>
>

>
>

>
>

>
>
>
>
>
>
>
> ---------------------------------------------
>
> Here is the topdcl_try.ascx file:
> ------------------------------------------
>
> <%@ Control ClassName=3D"topdcl" %>
>
>
>
> .--------------------------------------
> Here is the page load event:
>
> ---------------------------------------
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg=
s)
> Handles Me.Load
>
> =A0My_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, b=
ut
> 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!

Re: public variables in asp.net?

am 18.04.2008 23:24:20 von Web Search Store

Thanks a lot!

Scott
"Norm" wrote in message
news:ae0ed727-924b-4e39-85e9-5582eaf58a30@n14g2000pri.google groups.com...
On Apr 18, 12:01 pm, "Web Search Store"
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"
> %>
>
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
>
>
>
>
> Untitled Page
>
>
>
>
>
>


>
>

>
>

>
>

>
>
>
>
>
>
>
> ---------------------------------------------
>
> Here is the topdcl_try.ascx file:
> ------------------------------------------
>
> <%@ Control ClassName="topdcl" %>
>
>
>
> .--------------------------------------
> 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!