views:

32

answers:

1

I'm working with an already built ASP.Net custom date control, it seems pretty simple, but I don't know much about building custom controls.

The control is a text box that pops up the ajax toolkit CalendarExtender when clicked. The html looks like this.

<div style="display:inline; white-space:nowrap"> 
    <asp:TextBox runat="server" ID="txtCalender" CssClass="netcontrolstyle" Width="190px" onkeydown="if(event.which || event.keyCode){ if ((event.which == 13) || (event.keyCode == 13)) return false;}" />
</div>
<ajaxToolkit:CalendarExtender 
    runat="server"  
    ID="CalendarExtender1" 
    Format="MM/dd/yyyy" 
    TargetControlID="txtCalender" 
    PopupButtonID="CalenderImage" />

You'll notice the hard-coded width on the text box. How would I go about adding the style property to it so I can do something like this...

<uc1:datecontrol runat="server" ID="StartDate" style="width: 75px;"/>

I see in the code-behind some things are overriden, like enabled. I thought I'd do something similar for style.

public override bool Enabled
{
    get 
    { 
        return txtCalender.Enabled; 
    }
    set
    {
        txtCalender.Enabled = value;
    }
}

Overriding style doesn't seem to work the same way though unless I'm missing something.

+1  A: 

This should work (untested)

private string textboxStyle;
public string TextboxStyle
{
    get { return textboxStyle; }
    set { textboxStyle = value;}
}

In the control:

 <asp:TextBox runat="server" ID="txtCalender" CssClass="netcontrolstyle" Style="<%# TextboxStyle %>"  />

In the declaration

<uc1:datecontrol runat="server" ID="StartDate" TextboxStyle ="width: 75px;"/>
edosoft