控件结构如下:
Page
DataGrid
TemplateItem
PlaceHolderPlaceHolder在一般状态下并无内容,当某种特定的情况发生时,用一个UserControl放入PlaceHolder。也就是说,在模板列的模板中是没有UserControl对象的,它是被动态地加入模板中的。我的问题是:在DataGrid的UpdateCommand事件处理程序中,如何读取UserControl的内容?
Page
DataGrid
TemplateItem
PlaceHolderPlaceHolder在一般状态下并无内容,当某种特定的情况发生时,用一个UserControl放入PlaceHolder。也就是说,在模板列的模板中是没有UserControl对象的,它是被动态地加入模板中的。我的问题是:在DataGrid的UpdateCommand事件处理程序中,如何读取UserControl的内容?
if (ph != null)
UserControl ctl = (UserControl) ph.FindControl("UserControl")if (ctl != null)
{
...
}试过了,没用,找不到UserControl。
因为UserControl是在Page_Load事件中动态地加载,而在页面处理ViewState时该控件还没有加载,因此无法初始化它的值,在后面也就没办法读取了。