Setting Calendar size programatically

Posted on 2011-10-27
Last Modified: 2012-05-12
Hello experts,

I need to use code in the Page_load event of an form to set the height and width of a calendar control. I tried the following code (in VB) but it doesn't work.

Can you show me the correct way of doing it? Thanks.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 If Not IsPostBack  Then
 calendar1.Height = Unit.Pixel(616)
        calendar1.Width = Unit.Pixel(557)

Open in new window

Question by:adamtrask
    LVL 20

    Accepted Solution

    The method you have used to set the height/width of a calendar control is correct.

    In what way does it not "work"?

    If you simply set a calendar control on a page and use your code in the page load it works fine.

    The calendar is a table so if you have some CSS or JS that is affecting the page it may mess up the calendar's dimensions etc, but otherwise there is nothing to correct in what you have shown.

    Maybe if you could show some sample code of how the calendar is setup, styled, etc it would be more helpful.
    LVL 11

    Expert Comment

    <%@ Page Language="C#" AutoEventWireup="true" %>  
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">  
    <script runat="server">  
        protected void Button1_Click(object sender, System.EventArgs e)  
            DateTime afterSixMonths = DateTime.Today.AddMonths(6);  
            Calendar1.VisibleDate = afterSixMonths;  
    <html xmlns="">  
    <head id="Head1" runat="server">  
        <title>How to set change Calendar VisibleDate programmatically</title>  
        <form id="form1" runat="server">  
            <h2 style="color:DodgerBlue; font-style:italic;">  
                How to set change Calendar VisibleDate programmatically  
            <hr width="575" align="left" color="LightBlue" />  
                Font-Names="Book Antiqua"  
                     Font-Names="Arial CE"  
                <TodayDayStyle BackColor="DarkViolet" />  
                     Font-Names="Courier New Baltic"  
            <br />  
                Text="Set Calendar VisibleDate: After Six Months"  
    LVL 20

    Expert Comment

    LVL 7

    Assisted Solution

    that should indeed work, I've tried it on a blank project with both the units.pixel (557) and just 557.

    As ddayx10 requested, please could you post your code and any CSS you have.
    (If you've resolved it, please let us know :) )

    Author Closing Comment

    Thanks a lot

    Author Comment

    My apologies to all of you...

    I had a little accident with my computer and was completely distracted by this.
    I have some bad habits which occasionally cause some damage and this was one of them.

    Unfortunately I lost the code I was working on since the whole drive was lost.
    However, I started on a clean sheet and found that both ddayx10 and mr_nadger: are right. My code works the way it does. I am not sure if it was my CSS script, which is at a novice stage, could have been the culprit.

    Thank you and please accept my apologies for not responding sooner.


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    27 Experts available now in Live!

    Get 1:1 Help Now