Click to See Complete Forum and Search --> : How to expose properties in a user control?


ccrookston
10-10-2006, 02:42 PM
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:

<%@ Page CodeBehind="default.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="intellisoft._default" %>

And then later:

<uc1:navigation id="Navigation1" runat="server" />

Although it does work to do this:

<uc1:navigation id="Navigation1" ImageToDisplay=”valueHere” 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

sirpelidor
10-11-2006, 04:33 PM
open vs.net,
go to "autogen" section, expands the node.
locate the section where all your controls are being declare,
add the following line:


protected navigation Navigation1;


now do u Navigation1.ImageToDisplay = "valueHere" again....