Page_Init创建的控件无法在Page_Load中访问 [英] Page_Init created control can not accessed at Page_Load
本文介绍了Page_Init创建的控件无法在Page_Load中访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在Page_init中创建了用户控件.
它显示在表单上,我试图在页面加载时找到它,但我无法访问它.
这是我的代码
Page_Init
Hi,
I have created user control in Page_init.
It displays on form , i am trying to find it on page load but i am not able to access it.
Here is my code
Page_Init
for (int i = 1; i <= li_Count; i++)
{
Movable_Text mt = new Movable_Text();
mt.ID = "Movable_Text" + Convert.ToString(li_Count);
mt = LoadControl("~/Controls/Movable_Text.ascx") as Movable_Text;
DragPanelExtender drag_panel = new DragPanelExtender();
drag_panel = mt.FindControl("DPE_TextComments") as DragPanelExtender;
drag_panel.ID = "DPE_TextComments" + Convert.ToString(li_Count);
this.PH_Master_Page.Controls.Add(mt);
}
Page_Load
Page_Load
for (int i = 1; i <= li_Count; i++)
{
str_drag_panel = "DPE_TextComments" + Convert.ToString(li_Count);
DragPanelExtender drag_panel = new DragPanelExtender();
drag_panel = this.FindControl(str_drag_panel) as DragPanelExtender;
if (drag_panel == null)
{
//
}
else
{
//
}
}
其中 Movable_Text 是我的用户控件, PH_Master_Page 是我在母版页上的占位符,而 li_count 是我的静态变量,用于计算添加到控件上的控件数表格.
请指导我
where Movable_Text is my user control ,PH_Master_Page is my place holder on master page and li_count is my static variable used to count number of controls added on form.
Please guide me
推荐答案
尝试在PreInit
事件处理程序中创建控件.
ASP.NEt页面生命周期参考 [
Try creating the controls in thePreInit
event handler.
ASP.NEt Page Life-cycle reference[^]
首先将用户控件添加到母版页检查视图源以获取母版页查找控件ID,它将显示为ct100_等,将drag_panel = this.FindControl("ct00_")作为DragPanelExtender复制;
您将找到该控件.
First add user controls to master page check the view source for master page find control id it will displays like ct100_ etc copy drag_panel = this.FindControl("ct00_") as DragPanelExtender;
you will find that control.
这篇关于Page_Init创建的控件无法在Page_Load中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文