I created a calender with render option. It works perfectly on my local machine but it does not work on the server. I showed employee time sheet in a calender its working fine in local machine. But now i am published on the server its not working there.
My partial code is here:
if (e.Day.Date.Month == DateTime.Now.Month - 1)
{
if ((lblfromdate.Text != "") && (lbltodate.Text != ""))
{
if (e.Day.Date < Convert.ToDateTime(lblfromdate.Text))
{
e.Cell.Text = string.Empty;
e.Cell.BorderColor = System.Drawing.Color.White;
}
else
{
DataSet4TableAdapters.sp_getallholidayinfoTableAdapter TA = new DataSet4TableAdapters.sp_getallholidayinfoTableAdapter();
DataSet4.sp_getallholidayinfoDataTable DS = TA.GetData();
if (DS.Rows.Count > 0)
{
DataView DV = new DataView();
DV = DS.DefaultView;
string fromdate = Convert.ToString(lblfromdate.Text.Substring(5, 2) + "-" + lblfromdate.Text.Substring(8, 2) + "-" + lblfromdate.Text.Substring(0, 4));
string todate = Convert.ToString(lbltodate.Text.Substring(5, 2) + "-" + lbltodate.Text.Substring(8, 2) + "-" + lbltodate.Text.Substring(0, 4));
DV.RowFilter = "fldfromdate >=#" + fromdate + "# and fldfromdate <=#" + todate + "#";
if (DV.Count > 0)
{
string indate = Convert.ToString(DV[0]["fldfromdate"]);
string input = indate.Substring(6) + "-" + indate.Substring(0, 2) + "-" + indate.Substring(3, 2);
if (Convert.ToString(e.Day.Date.ToShortDateString()) == input)
{
e.Cell.Controls.Clear();
e.Cell.Text = "Holiday";
e.Cell.BackColor = System.Drawing.Color.BlueViolet;
}
}
}
}
}
}
My design code:
<asp:Calendar ID="Calendar2" runat="server" BackColor="White"
BorderColor="Black" BorderWidth="2px" Enabled="False"
Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
Height="183px" NextPrevFormat="FullMonth" ShowGridLines="True"
Width="659px" OnDayRender="Calendar2_DayRender" ShowNextPrevMonth="False">
<DayHeaderStyle BackColor="#6699FF" BorderStyle="Solid"
Font-Bold="True" Font-Size="8pt" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt"
ForeColor="#333333" VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle ForeColor="White" />
<TitleStyle BackColor="White" BorderColor="Black" BorderStyle="None"
Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
</asp:Calendar>
Double check the Regional settings on the server compared to your development server.
Usually when you are building dates as strings from strings, and then your servers change from one region to another, there will be problems with date formats
So if you are building a string for “dd-MM-yyyy” then the server might be looking for “MM-dd-yyyy”