gpt4 book ai didi

c# - 我从官方 MCTS 考试 70-562 书中得到的小测试程序没有触发事件

转载 作者:太空宇宙 更新时间:2023-11-03 22:17:35 26 4
gpt4 key购买 nike

我从官方 MCTS 考试 70-562 书中得到的小测试程序没有触发事件。我在 Debug模式下跟踪了计算机逻辑,它甚至没有进入我的事件,即使我已经设置好一切来处理它们。所以最大的问题是做错了什么?

    **CODE BEHIND FILE:**

public partial class Calendar : System.Web.UI.Page
{
Hashtable _scheduleData;

protected void Page_Load(object sender, EventArgs e)
{
_scheduleData = GetSchedule();

Calendar1.Caption = "Personal Schedule";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.MonthYear;
Calendar1.ShowGridLines = true;
Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Left;
Calendar1.DayStyle.VerticalAlign = VerticalAlign.Top;
Calendar1.DayStyle.Height = new Unit(75);
Calendar1.DayStyle.Width = new Unit(100);
Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.Cornsilk;
Calendar1.TodaysDate = new DateTime(2009, 2, 1);
Calendar1.VisibleDate = Calendar1.TodaysDate;
}

private Hashtable GetSchedule()
{
Hashtable schedule = new Hashtable();

schedule["2/9/2009"] = "Vactican Day";
schedule["2/18/2009"]="Budget planning meeting @ 3:00pm";
schedule["2/24/2009"]="Dinner plans with friends @ 7:00pm";
schedule["2/27/2009"]="Travel Day";
schedule["3/5/2009"]="Conf call @ 1:00pm";
schedule["3/10/2009"]="Meet with art director for lunch";
schedule["3/27/2009"]="Vacation Day";

return schedule;
}

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
LabelAction.Text = "Selection changed to: " + Calendar1.SelectedDate.ToShortDateString();
}

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
LabelAction.Text = "Month changed to : " + e.NewDate.ToShortDateString();
}

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (_scheduleData[e.Day.Date.ToShortDateString()] != null)
{
//Literal lit = new Literal();
lit.Text = "<br />";
e.Cell.Controls.Add(lit);

//Label lbl = new Label ();
lbl.Text = (string)_scheduleData[e.Day.Date.ToShortDateString()];
lbl.Font.Size=new FontUnit (FontSize.Small);
e.Cell.Controls.Add(lbl);
}
}
}


**ASPX CODE:**

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calendar.aspx.cs" Inherits="Calendar" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 350px">
<br />
<asp:Label ID="LabelAction" runat="server" Text=" "></asp:Label>
<br />
<asp:Literal ID="lit" runat="server"></asp:Literal>
<br />
<asp:Label ID="lbl" runat="server" Text=" "></asp:Label>
<br />
<asp:Calendar ID="Calendar1" runat="server"
OnSelectionChanged="Calendar1_SelectionChanged"
OnVisibleMonthChanged="Calendar1_VisibleMonthChanged"
OnDayRender="Calendar1_DayRender" SelectionMode="DayWeekMonth"> </asp:Calendar>
<br />
<asp:Label ID="Label1" runat="server" Text=" "></asp:Label>
<br />
</div>
</form>
</body>
</html>

最佳答案

AutoEvent wireup 没有发生,因为您没有将 .cs 文件的方法链接到 .aspx 页面上的控件

将您的代码更改为在 aspx 页面源代码中填充:

       <asp:Calendar  ID="Calendar1" runat="server" 
ondayrender="Calendar1_DayRender"
onselectionchanged="Calendar1_SelectionChanged"
onvisiblemonthchanged="Calendar1_VisibleMonthChanged"></asp:Calendar>

关于c# - 我从官方 MCTS 考试 70-562 书中得到的小测试程序没有触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4485917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com