CptSupermrkt
CptSupermrkt

Reputation: 7114

Height and Width properties for UserControls

I have a User Control called EmployeesCheckBoxList, which just contains a standard CheckBoxList that is populated with Employees. I can easily create properties in my EmployeesCheckBoxList that get/set the Width/Height of the CheckBoxList within my UserControl:

public Unit Height
{
    get { return cblEmployees.Height; }
    set { cblEmployees.Height = value; }
}

public Unit Width
{
    get { return cblEmployees.Width; }
    set { cblEmployees.Width = value; }
}

And then in my .aspx page I can set the Width and Height at runtime with:

<MyUserControls:EmployeesCheckBoxList runat="server"
    Height="100px" Width="150px"/>

And those properties properly alter the dimensions of the Web Control inside my User Control.

What I'd like to know is, is it possible to alter the dimensions of the entire User Control, rather than just take the values as properties and then modify the controls within the User Control?

For example, let's say my User Control also had other web controls in it, like a Button. If I set the above Height and Width properties to 100px and 150px, what I would LIKE to achieve is not modifying each web control with those measurements, but rather set the viewable space of the User Control to those dimensions. Meaning that in the case of a CheckBoxList full of Employees and a Button, and set the dimensions to 100px by 150px, the entire contents of the User Control wouldn't fit, and the User Control would become scrollable within those dimensions.

This is how the regular CheckBoxList works. If you have like 100 items in it, but set the Height to 100px, only a few items are visible at once, and the list is scrollable within that 100px space.

Upvotes: 1

Views: 5808

Answers (1)

Umesh
Umesh

Reputation: 2732

Use a div in your user control and set the width and height properties to it. Also include overflow:scroll under it's style.

Upvotes: 3

Related Questions