Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Setting Calendar size programatically

Posted on 2011-10-27
6
Medium Priority
?
293 Views
Last Modified: 2012-05-12
Hello experts,

I need to use code in the Page_load event of an Asp.net 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

0
Comment
Question by:adamtrask
6 Comments
 
LVL 20

Accepted Solution

by:
ddayx10 earned 1000 total points
ID: 37042202
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.
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 37042771
<%@ Page Language="C#" AutoEventWireup="true" %>  
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)  
    {  
        DateTime afterSixMonths = DateTime.Today.AddMonths(6);  
        Calendar1.VisibleDate = afterSixMonths;  
    }  
</script>  
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>How to set change Calendar VisibleDate programmatically</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:DodgerBlue; font-style:italic;">  
            How to set change Calendar VisibleDate programmatically  
        </h2>  
        <hr width="575" align="left" color="LightBlue" />  
        <asp:Calendar  
            ID="Calendar1"  
            runat="server"  
            NextPrevFormat="FullMonth"  
            SelectionMode="Day"  
            ForeColor="WhiteSmoke"  
            DayNameFormat="Full"  
            Font-Names="Book Antiqua"  
            Font-Size="Medium"  
            > 
            <DayHeaderStyle  
                 BackColor="DarkRed"  
                 />  
            <DayStyle  
                 BackColor="DarkSalmon"  
                 BorderColor="Salmon"  
                 BorderWidth="1"  
                 Font-Bold="true"  
                 Font-Italic="true"  
                 />  
            <NextPrevStyle  
                 Font-Italic="true"  
                 Font-Names="Arial CE"  
                 />  
            <OtherMonthDayStyle  
                 BackColor="IndianRed"  
                 BorderColor="SandyBrown"  
                 Font-Overline="true"  
                 />  
            <SelectedDayStyle  
                 BackColor="Green"  
                 BorderColor="SpringGreen"  
                 />  
            <TodayDayStyle BackColor="DarkViolet" />  
            <TitleStyle  
                 BackColor="DarkSlateBlue"  
                 Height="35"  
                 Font-Size="Large"  
                 Font-Names="Courier New Baltic"  
                 />  
        </asp:Calendar>  
        <br />  
        <asp:Button  
            ID="Button1"  
            runat="server"  
            Text="Set Calendar VisibleDate: After Six Months"  
            Font-Bold="true"  
            OnClick="Button1_Click"  
            ForeColor="DarkBlue"  
            Height="45"  
            />  
    </div>  
    </form>  
</body>  
</html>  
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 37042795
?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Assisted Solution

by:mr_nadger
mr_nadger earned 1000 total points
ID: 37043706
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 :) )
0
 

Author Closing Comment

by:adamtrask
ID: 37051126
Thanks a lot
0
 

Author Comment

by:adamtrask
ID: 37051130
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.

Adam
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

581 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