[thelist] .NET: Public variable set in user control

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Thu Oct 12 11:08:35 CDT 2006


		   Not to disparage Stephen's excellent work, but technically public variables are exposed as fields, not as properties.  To create a true property, you need to define it as such with Get and/or Set methods.

Public Property ImageToDisplay() As String
   Get
      Return [some private variable which holds this information]
   End Get
   Set(ByVal Value As String)
      [some private variable which holds this information] = Value
   End Set
End Property

   That being said, of course, we'll probably need to see more code (unless defining your fields as full-fledged properties solves your problem).

Peter

				From: "Casey Crookston" caseyc at IntelliSoftmn.com

Ok, according to page 260 of ASP.NET Unleashed (1.1), "All public
variables declared in the user control file are exposed as properties of
the user control." So I have a user control called navigation.ascx. In
navigation.ascx.vb I declare a public variable called ImageToDisplay as
a string. Then, in the page that is referring to the user control, I
need to programmatically set the value of this string. In the HTML we
declare the control as such:

]]>

And then later:

Although it does work to do this:

runat="server" />

I need to set the value programmatically. This in the code-behind

Navigation1.ImageToDisplay = "valueHere"

returns this error:

'ImageToDisplay' is not a member of 'System.Web.UI.UserControl'.

As far as I can tell, I'm doing this exactly as the example in the book.
What else do I need to do?

Thanks,

Casey



More information about the thelist mailing list