0

I've created a Table User control. In each cell in table, there are checkboxes. How can I access the attributes of selected checkboxes in the default.aspx page.

I've dragged Table user control into default.aspx

  <uc1:SchTable ID="SchTime1" runat="server" />

Am relatively new to User Control. Was trying it out because of maintainability. I managed to get the codes to work by hard coding the table (not using user control) on the same page as default.aspx though

1 Answers1

0

Add a property to the UserControl that accesses and returns the data you want.

In SchTable you can add any number of public properties and methods you want. Some examples:

public IEnumerable<ListItem> SelectedItems
{
   get 
   {
       return ACheckboxList.Items.Cast<ListItem>().Where(i => i.Selected); 
   }
}

public IEnumerable<Checkbox> GetAllCheckboxes()
{
     //Find and return the checkboxes here just like you would in the page
}

And then in the Default page, you can access that information:

var selected = SchTime1.SelectedItems;
var checkboxes = SchTime1.GetAllCheckboxes();

There is a MSDN tutorial here that goes more into details on all this.

PHeiberg
  • 29,411
  • 6
  • 59
  • 81