在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