在dayrender事件中添加控件後,是否有辦法在以後找到控件?我試過如何在asp.net日曆控件中找到控件
calendar.FindControl("lblSample")
但沒有成功。
下面是一些我的代碼更清晰:渲染事件和頁面加載
protected void calSample_DayRender(object sender, DayRenderEventArgs e)
{
Label lblSample = new Label();
lblSample.ID = "lblSample";
lblSample.Text = "Sample";
e.Cell.Controls.Add(lblSample);
}
一天之後完全,我有一個鏈接按鈕事件,我嘗試並獲得控制權交還給
protected void lbtnSave_Click(object sender, EventArgs e)
{
//Not working
Label lblSample = calSample.FindControl(lblSample);
//Also can't get to work, this was using Ross' suggestion and the recursive find function he wrote about. I'm probably just not using it correctly.
Label lblSample = ControlFinder.FindControl<Label>(calSample, "lblSample");
}
'FindControl'不會遞歸搜索,所以你將需要使自己的,不僅是當前兒童搜索,但內的任何容器的孩子。 –
您可能需要緩衝多個圖層,例如如果你的窗體有一個你有控制權的asp:Panel,你將需要導航Form => Panel => Control。 – StuartLC
請參閱http://stackoverflow.com/questions/2209854/find-all-child-controls-of-specific-type-using-enumerable-oftypet-or-linq – abatishchev