Set the width of a custom control with 2 controls inside

F

Fernando Lopes

Hi there.
I'm developing a custom controls.
Inside this custom control, I want to put 2 controls: one textbox and one
dropdownlist.
I want to create a Width property for this custom control.
The dropdownlist shoul have 50px.
The textbox must have variable width;

So, how can I set this property correctly?
A property Width, and set the this value - 50px?

Did someone do that?

Tks.

Fernando Lopes
 
K

Kannan.V [MCSD.net]

hi,

write the line to set the width of the textbox and the dropdown in your
Property accessor method "SET"
The code block shd look like this...

Public .........ControlWidth
{
Get
{
return txtTextbox.Width
}
SET
{
txtTextBox.Width = value;
dpDropdown.width = value
}
}

Once you enter the width in the property browser window for your custom
control, the width of your custom added controls will also be set.

Hope this helps
Kannan.V
 
F

Fernando Lopes

Hi Kannan.
But, if I set 100px to custom control width I will get a textbox with 100px
and a dropdown with a 100px totalize a control with 200px.

It's not what am I want. I want a control with a textbox with 50px and a
dropdown with 50px

Tks.

Fernando
 
K

Kannan.V [MCSD.net]

hi fernando,

Am not clear of how your are trying to achieve the rendering.
Are you rendering the text box and the dropdown on a single line.

The way I described you was to render the textbox and dropdown controls
using a table cell.
Each cell will contain 1 control
in this way when you set the width property, the code inside the property
will set the width of the textbox to 100Px and the width of the dropdown to
100px.

Are you by any chance adding the width of the controls present on your
custom control.
If am not still clear to you, post your code and I will try to give you some
solution.

Regds
Kannan.V
 
L

lisa

Hi Fernando,

You want to override the Width property of your control, and set the
textbox width inside of it.

This is the VB.NET version:

Public Overrides Property Width() As System.Web.UI.WebControls.Unit
Get
Return CType(ViewState("Width"), Unit)
End Get

Set(ByVal Value As System.Web.UI.WebControls.Unit)
If Not Value.IsEmpty Then
Me.EnsureChildControls()
ViewState("Width") = Value
_myTextBox.Width = CType(Value.Value - 50, Unit)
End If
End Set
End Property

See? The Get works like normal, and the Set takes the value and then
sets the width of the textbox equal to 50 pixels less than the overall
width.

Value.Value is because the Value property of Unit is what'll give you
the number of units. You can replace the "50" with
_myDropDown.Width.Value, so that if you change the width of the
dropdown in your code, you won't have to change it in two places.

HTH,
Lisa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top