Calendar Control Behaving Badly

263 Views Asked by At

I have a problem with a user control containing a calendar control. It looks OK in the design view in Visual Studio 2015:

This is how it looks in design view

However, in the browser, any browser, it looks like this:

This is how it looks in the browser

I have tried to set the width to 330px wherever I can think of, but it always seems to get the width 1084 somehow!?

Where is the problem?

Here is the code for the user control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TimeKalender.ascx.cs" Inherits="Blodbanken.TimeKalender" %>

<link rel="Stylesheet" type="text/css" href="StyleSheet1.css" id="style" runat="server" visible="false" />

<div class="kalender" style="width:330px;">
    <asp:Calendar ID="Calendar1"  runat="server" BackColor="White" BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" Width="100%">
        <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" />
        <DayStyle BackColor="#CCCCCC" />
        <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
        <OtherMonthDayStyle ForeColor="#999999" />
        <SelectedDayStyle BackColor="#E60000" ForeColor="White" />
        <TitleStyle BackColor="Red" BorderStyle="None" Font-Bold="True" Font-Size="12pt" ForeColor="White" Height="12pt" />
        <TodayDayStyle BackColor="#999999" ForeColor="White" />
    </asp:Calendar>
</div>

<asp:Label ID="lblLedigeTimer" runat="server" Text="Available appointments:" Font-Bold="True"></asp:Label>
<br />

<asp:CheckBoxList ID="CheckBoxList1" runat="server">
    <asp:ListItem>08:00 </asp:ListItem>
    <asp:ListItem>09:00 </asp:ListItem>
    <asp:ListItem>10:00 </asp:ListItem>
    <asp:ListItem>11:00 </asp:ListItem>
    <asp:ListItem>12:00 </asp:ListItem>
    <asp:ListItem>13:00 </asp:ListItem>
    <asp:ListItem>14:00 </asp:ListItem>
    <asp:ListItem>15:00 </asp:ListItem>
</asp:CheckBoxList>

<asp:Button ID="Button1" runat="server" Text="Book it!" Width="119px" />
2

There are 2 best solutions below

1
Schpenn On BEST ANSWER

Mystery solved!

It turned out that the asp:calendar-tag translates into a bunch og table-tags. And deeply nested in there are some a-tags that were affected by the css intended for the nav-menu. enter image description here

Thanks for your input!

3
Derek Van Cuyk On

I'm not sure if this is it since you stated that you set the width to 330px but in the sample HTML you set the width to 100%

<asp:Calendar ... NextPrevFormat="ShortMonth" Width="100%">

Take that out the width definition and let the size be defined by the parent div