views:

325

answers:

2

In a regular .aspx page, you can access public properties from the codebehind. Is there any way to do a similar thing in a user control. For example, in the following code 'List' is public property of the codebehind of the user control and yet it is not accessible.

<% foreach (TripTeam team in List) { %>
<div>
    <label><%= team.Name %></label>
</div>                    
<%} %>
+1  A: 

You can access the public properties of a UserControl from your .aspx page. Here's an example

<script runat="server">
public string Caption { get { return _caption.Text; } set { _caption.Text = value; } }
public string Text{ get { return _tb1.Text; } set { _tb1.Text = value; } }

<div>
<asp:Label ID="_caption" runat= "server" class="caption" /><br />
<asp:TextBox ID="_tb1" runat="server" CssClass="textBox" Width="25px" />

Then on your aspx page, you can set the Text and Caption properties within your user control:

<uc1:CaptionText ID="ct1" runat="server" Caption="User name" />
Barryman9000
A: 

You need to say 'userControlId.List' to access the property when accessing a property in the control from a page which uses the control.

CRice