RadDatePicker Q1 2012 static width when setting SelectedDate via codebehind

2 posts, 0 answers
  1. Florian
    Florian avatar
    1 posts
    Member since:
    Nov 2011

    Posted 08 Mar 2012 Link to this post

    I have a problem with setting the width of an RadDatePicker contro and set the SelectedDate property via the codebehind.
    Her is my sample code APSX:

    <telerik:RadDatePicker ID="DatePicker1" runat="server" Width="30px" AutoPostBack="true">
    <Calendar CultureInfo="en-US" FirstDayOfWeek="Monday" ID="Calendar1" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x" runat="server"/>
    <DateInput ID="DateInputFrom" DateFormat="dd.MM.yyyy" DisplayDateFormat="dd.MM.yyyy" runat="server"/>
    </telerik:RadDatePicker>

    And here the Codebhind:

    protected void Page_Load(object sender, EventArgs e)
    {
    DatePicker1.SelectedDate = DateTime.Now;
    }

    Is there any workaround to set the correct Width?

     

  2. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 12 Mar 2012 Link to this post

    Florian:

    I copied over your code and ran it. By simply changing the property setting for the RadDatePicker to "Width="100px" the full date displays correctly. I believe that this width setting takes in the entire width of the component, textbox and popup calendar combined.

    Default.aspx:
    <telerik:RadDatePicker ID="DatePicker1" runat="server" Width="100px" AutoPostBack="true">
        <calendar cultureinfo="en-US" firstdayofweek="Monday" id="Calendar1" usecolumnheadersasselectors="False"
            userowheadersasselectors="False" viewselectortext="x" runat="server" />
        <dateinput id="DateInputFrom" dateformat="dd.MM.yyyy" displaydateformat="dd.MM.yyyy"
            runat="server" />
    </telerik:RadDatePicker>

    Alternatively, you can remove the width setting from the RadDatePicker definition and set it as a property of the dateinput textbox:

    Default.aspx:
    <telerik:RadDatePicker ID="DatePicker1" runat="server" AutoPostBack="true">
        <calendar cultureinfo="en-US" firstdayofweek="Monday" id="Calendar1" usecolumnheadersasselectors="False"
            userowheadersasselectors="False" viewselectortext="x" runat="server" />
        <dateinput id="DateInputFrom" dateformat="dd.MM.yyyy" displaydateformat="dd.MM.yyyy" Width="30px"
            runat="server" />
    </telerik:RadDatePicker>

    The latter works better and the "30px" assignment displays the full date.

    Regards,
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top