VWD 2010 C# を使用。Default.aspx (.cs)。
どうなるか: ボタンを押すと、ラベルの色が に変わりますID = "Day31"
。この例では、月の 31 日であるとします。ボタンとラベルは、「MainContent」内のテーブル内に配置されます。
protected void Red_Click(object sender, EventArgs e)
{
ContentPlaceHolder MainContent = Page.Master.FindControl("MainContent") as ContentPlaceHolder;
int theday;
theday = System.DateTime.Now.Day; // example the day is 31st
string str="Day"+theday;
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + str+ "');", true);
Label dayLabel = FindControl(str) as Label;
dayLabel.BackColor = System.Drawing.Color.Red; // this line error, "Null"
}
質問:Null
このコード行にエラー メッセージがあるのはなぜですか?