在我正在开发的网站上,我有一个(现在)2页,每页有2个日历控件,显示课程日期,一个用于初学者课程,一个用于高级课程。
当最初导航到page1时,控件正常工作(点击时)。
但是当导航到第2页时,控件(点击时)要么不工作,要么实际导航回第1页。
就好像日历控件被缓存或类似的东西,只记得它在网站上首次使用的位置。
我也试过禁用页面上的所有缓存都无济于事。
我不想使用javascript日历弹出窗口,因为你必须单击一个按钮才能显示它。
第一页的HTML:
<div class="divcol">
<asp:Calendar ID="calBegEventDecor" runat="server" BackColor="White" BorderColor="#2d0231" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#5b0462" Height="200px" Width="220px" Font-Bold="True" OnDayRender="calBegEventDecor_DayRender">
<DayHeaderStyle BackColor="#9e06ac" ForeColor="#ffffff" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#ffffff" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#9e06ac" Font-Bold="True" ForeColor="#ffffff" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#5b0462" BorderColor="#5b0462" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#ffffff" Height="25px" HorizontalAlign="Center" />
<WeekendDayStyle BackColor="#f9cefd" />
</asp:Calendar>
</div>
<div class="divcol">
<asp:Calendar ID="calAdvEventDecor" runat="server" BackColor="White" BorderColor="#2d0231" BorderWidth="1px"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#5b0462" Height="200px" Width="220px" Font-Bold="True" OnDayRender="calAdvEventDecor_DayRender">
<DayHeaderStyle BackColor="#9e06ac" ForeColor="#ffffff" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#ffffff" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#9e06ac" Font-Bold="True" ForeColor="#ffffff" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#5b0462" BorderColor="#5b0462" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#ffffff" Height="25px" HorizontalAlign="Center" />
<WeekendDayStyle BackColor="#f9cefd" />
</asp:Calendar>
</div>
第一页代码:
public partial class PlanningCourses : System.Web.UI.Page
{
private List<DateTime> beginnerCourseDates = new List<DateTime>();
private List<DateTime> advancedCourseDates = new List<DateTime>();
private double beginnersEventDecorationSingle = 4200.00;
private double beginnersEventDecorationGroup = 3700.00;
private double advancedEventDecorationSingle = 9450.00;
private double advancedsEventDecorationGroup = 8900.00;
public double BeginnersEventDecorationGroup
{
get { return beginnersEventDecorationGroup; }
set { beginnersEventDecorationGroup = value; }
}
public double BeginnersEventDecorationSingle
{
get { return beginnersEventDecorationSingle; }
set { beginnersEventDecorationSingle = value; }
}
public double AdvancedEventDecorationGroup
{
get { return advancedsEventDecorationGroup; }
set { advancedsEventDecorationGroup = value; }
}
public double AdvancedEventDecorationSingle
{
get { return advancedEventDecorationSingle; }
set { advancedEventDecorationSingle = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
//Suppose that you have the following list of dates below
beginnerCourseDates.Add(Convert.ToDateTime("2016/09/5"));
beginnerCourseDates.Add(Convert.ToDateTime("2016/09/19"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/6"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/7"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/8"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/20"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/21"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/22"));
}
protected void calBegEventDecor_DayRender(object sender, DayRenderEventArgs e)
{
//Set Default properties
//if the date is in the past, disable it and mark it gray else just disable it
e.Day.IsSelectable = false;
if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) < Convert.ToDateTime(DateTime.Now.ToShortDateString()))
e.Cell.BackColor = System.Drawing.Color.FromArgb(217, 217, 217); //System.Drawing.Color.Gray;
else if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) == Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
e.Cell.BorderStyle = BorderStyle.Solid;
e.Cell.BorderWidth = 2;
e.Cell.BorderColor = System.Drawing.Color.FromArgb(91, 4, 98);
e.Cell.BackColor = System.Drawing.Color.FromArgb(242, 133, 250); //System.Drawing.Color.Green;
}
//Now loop through the list of dates and make it
//Selectable
foreach (DateTime d in beginnerCourseDates)
{
if (Convert.ToDateTime(d.ToShortDateString()) >= Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
calBegEventDecor.SelectedDates.Add(d);
if (e.Day.IsSelected)
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(158, 6, 172); //System.Drawing.Color.Green;
//e.Cell.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); //System.Drawing.Color.Green;
//e.Day.IsSelectable = true;
}
}
}
}
protected void calAdvEventDecor_DayRender(object sender, DayRenderEventArgs e)
{
//Set Default properties
//if the date is in the past, disable it and mark it gray else just disable it
e.Day.IsSelectable = false;
if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) < Convert.ToDateTime(DateTime.Now.ToShortDateString()))
e.Cell.BackColor = System.Drawing.Color.FromArgb(217, 217, 217); //System.Drawing.Color.Gray;
else if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) == Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
e.Cell.BorderStyle = BorderStyle.Solid;
e.Cell.BorderWidth = 2;
e.Cell.BorderColor = System.Drawing.Color.FromArgb(91, 4, 98);
e.Cell.BackColor = System.Drawing.Color.FromArgb(242, 133, 250); //System.Drawing.Color.Green;
}
//Now loop through the list of dates and make it
//Selectable
foreach (DateTime d in advancedCourseDates)
{
if (Convert.ToDateTime(d.ToShortDateString()) >= Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
calAdvEventDecor.SelectedDates.Add(d);
if (e.Day.IsSelected)
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(158, 6, 172); //System.Drawing.Color.Green;
//e.Cell.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); //System.Drawing.Color.Green;
//e.Day.IsSelectable = true;
}
}
}
}
}
第二页的HTML:
<div class="divcol">
<asp:Calendar ID="calBegBalloonDecor" runat="server" BackColor="White" BorderColor="#2d0231" BorderWidth="1px"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#5b0462" Height="200px" Width="220px" Font-Bold="True" OnDayRender="calBegBalloonDecor_DayRender">
<DayHeaderStyle BackColor="#9e06ac" ForeColor="#ffffff" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#ffffff" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#9e06ac" Font-Bold="True" ForeColor="#ffffff" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#5b0462" BorderColor="#5b0462" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#ffffff" Height="25px" HorizontalAlign="Center" />
<WeekendDayStyle BackColor="#f9cefd" />
</asp:Calendar>
</div>
<div class="divcol">
<asp:Calendar ID="calAdvBalloonDecor" runat="server" BackColor="White" BorderColor="#2d0231" BorderWidth="1px"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#5b0462" Height="200px" Width="220px" Font-Bold="True" OnDayRender="calAdvBalloonDecor_DayRender">
<DayHeaderStyle BackColor="#9e06ac" ForeColor="#ffffff" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#ffffff" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#9e06ac" Font-Bold="True" ForeColor="#ffffff" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#5b0462" BorderColor="#5b0462" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#ffffff" Height="25px" HorizontalAlign="Center" />
<WeekendDayStyle BackColor="#f9cefd" />
</asp:Calendar>
</div>
第二页代码:
public partial class BalloonCourses : System.Web.UI.Page
{
private List<DateTime> beginnerCourseDates = new List<DateTime>();
private List<DateTime> advancedCourseDates = new List<DateTime>();
private double beginnersBalloonDecorSingle = 4700.00;
private double beginnersBalloonDecorGroup = 4200.00;
private double advancedBalloonDecorSingle = 6950.00;
private double advancedsBalloonDecorGroup = 6450.00;
public double BeginnersBalloonDecorGroup
{
get { return beginnersBalloonDecorGroup; }
set { beginnersBalloonDecorGroup = value; }
}
public double BeginnersBalloonDecorSingle
{
get { return beginnersBalloonDecorSingle; }
set { beginnersBalloonDecorSingle = value; }
}
public double AdvancedBalloonDecorGroup
{
get { return advancedsBalloonDecorGroup; }
set { advancedsBalloonDecorGroup = value; }
}
public double AdvancedBalloonDecorSingle
{
get { return advancedBalloonDecorSingle; }
set { advancedBalloonDecorSingle = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
//Suppose that you have the following list of dates below
beginnerCourseDates.Add(Convert.ToDateTime("2016/09/12"));
beginnerCourseDates.Add(Convert.ToDateTime("2016/09/26"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/13"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/14"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/27"));
advancedCourseDates.Add(Convert.ToDateTime("2016/09/28"));
}
protected void calBegBalloonDecor_DayRender(object sender, DayRenderEventArgs e)
{
//Set Default properties
//if the date is in the past, disable it and mark it gray else just disable it
e.Day.IsSelectable = false;
if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) < Convert.ToDateTime(DateTime.Now.ToShortDateString()))
e.Cell.BackColor = System.Drawing.Color.FromArgb(217, 217, 217); //System.Drawing.Color.Gray;
else if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) == Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
e.Cell.BorderStyle = BorderStyle.Solid;
e.Cell.BorderWidth = 2;
e.Cell.BorderColor = System.Drawing.Color.FromArgb(91, 4, 98);
e.Cell.BackColor = System.Drawing.Color.FromArgb(242, 133, 250); //System.Drawing.Color.Green;
}
//Now loop through the list of dates and make it
//Selectable
foreach (DateTime d in beginnerCourseDates)
{
if (Convert.ToDateTime(d.ToShortDateString()) >= Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
calBegBalloonDecor.SelectedDates.Add(d);
if (e.Day.IsSelected)
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(158, 6, 172); //System.Drawing.Color.Green;
//e.Cell.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); //System.Drawing.Color.Green;
//e.Day.IsSelectable = true;
}
}
}
}
protected void calAdvBalloonDecor_DayRender(object sender, DayRenderEventArgs e)
{
//Set Default properties
//if the date is in the past, disable it and mark it gray else just disable it
e.Day.IsSelectable = false;
if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) < Convert.ToDateTime(DateTime.Now.ToShortDateString()))
e.Cell.BackColor = System.Drawing.Color.FromArgb(217, 217, 217); //System.Drawing.Color.Gray;
else if (Convert.ToDateTime(e.Day.Date.ToShortDateString()) == Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
e.Cell.BorderStyle = BorderStyle.Solid;
e.Cell.BorderWidth = 2;
e.Cell.BorderColor = System.Drawing.Color.FromArgb(91, 4, 98);
e.Cell.BackColor = System.Drawing.Color.FromArgb(242, 133, 250); //System.Drawing.Color.Green;
}
//Now loop through the list of dates and make it
//Selectable
foreach (DateTime d in advancedCourseDates)
{
if (Convert.ToDateTime(d.ToShortDateString()) >= Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
calAdvBalloonDecor.SelectedDates.Add(d);
if (e.Day.IsSelected)
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(158, 6, 172); //System.Drawing.Color.Green;
//e.Cell.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); //System.Drawing.Color.Green;
//e.Day.IsSelectable = true;
}
}
}
}
}
答案 0 :(得分:0)
控件通常不会在任何地方重定向。很可能您在click事件中有一个执行该重定向的代码。要解决问题,请在第2页上删除该代码,看看它是否仍然重定向。如果,假设控件被“缓存”,他们应该继续重定向而不需要代码。如果页面行为不同(没有代码没有重定向) - 再次启用代码并逐行检查。可以是您在会话中保留第1页上的日期,在第2页上,您再次检查该会话,然后重定向。