在Page_Init之后,初始处理程序未触发 [英] Init Handler Not Firing After Page_Init

查看:56
本文介绍了在Page_Init之后,初始处理程序未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好的天才,


我在试图让一个占位符触发的初始化处理程序时遇到问题

control
初始化阶段的
。我已将此问题发布到其他3个ASP.NET

论坛,

并且没有人愿意触摸它。


我试图将文字控件附加到占位符:

< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]>

< [+]> - < [+]> - < [+]> - < [+] > - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]>


/ * -------------------- ---------------------------------------------- * /

/ * ------------------------------------------ ------------------------ * /

void plc_hldr_Control_Init(object sender,EventArgs e)

{

int ndx = 1;


// Dyn_Control_Placeholder.Controls.Add

this.Controls.Add

(新的LiteralControl(< br>在init< br>"上添加1));

}

/ * ---- ------------------------------ -------------------------------- * /

/ * ------ -------------------------------------------------- ---------- * /

void Page_Init(对象发送者,EventArgs e)

{

int ndx = 2 ;


//为''Init'添加一个事件处理程序。


Dyn_Control_Placeholder.Init

+ = new System.EventHandler(plc_hldr_Control_Init);

}

/ * ---------------------- -------------------------------------------- * /

/ * -------------------------------------------- ---------------------- *


< [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < ; [+]> - < [+]> - < [+]> - < [+]>

< [+]> - < [+ ]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> ; - < [+]> - < [+]> - < [+]> - < [+]>


...而且没什么发生了:Init处理程序从未被解雇。


我把我的代码放在调试中ger,在Init处理程序上设置断点

(plc_hldr_Control_Init),并且从未到达断点。


我已阅读SDK文档,并且我以为我弄明白了:

< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+ ]> - < [+]>

< [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < ; [+]> - < [+]>

.NET Framework类库


Control.Init事件[C#]


C#

公共事件EventHandler Init;


事件数据

事件处理程序接收参数类型为EventArgs。


备注

服务器控件应执行所需的任何初始化步骤

来创建和设置实例。您不能在此活动中使用视图状态信息

;它还没有填充。在此事件期间,您不应该访问另一个

服务器控件,无论它是否是该控件的子级或

父级。其他服务器控件不一定要创建

并准备好访问。


示例

[C#]以下示例分配一个自定义事件处理程序,Control_Init,

到控件的init事件,myControl,当在包含控件的页面上调用Page_Init方法时。$ br / b >

void Page_Init(对象发送者,EventArgs e)

{

//为''Init'添加事件处理程序。

myControl.Init + = new System.EventHandler(Control_Init);

}


void Control_Init(object sender,EventArgs e)

{

Response.Write("最初对象的ID:" + myControl.ID);

//更改ID属性。

myControl.ID =" TestControl";

Response.Write("< br>已更改的ID:" + myControl.ID); < br $> b $ b}


? 2001-2002微软公司。保留所有权利。


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+ ]> - < [+]>

< [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < ; [+]> - < [+]>


我不明白的一件事是:myControl在哪里?来自

给出的例子?


只是为了笑,我将Init功能移到了Page_Init处理程序中:

< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]>< [+]>< [+]>

< [+]> - < [+]> - < [+]>< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> [< [+]> - < [+]>< [+]>
/ * ------------------------------------------- ----------------------- * /

/ * --------------- -------------------------------------------------- - * /

public void plc_hldr_Control_Init(object sender,EventArgs e)

{

int ndx = 1;

// Dyn_Control_Placeholder.Controls.Add

this.Controls.Add

(新的LiteralControl(< br>在init< br>上添加1) ));

}

/ * -------------------------- ---------------------------------------- * /

/ * ------------------------------------------ ------------------------ * /

public void Page_Init(object sender,EventArgs e)

$

int ndx = 2;


//为''Init'添加事件处理程序。


// Dyn_Control_Placeholder.Init

// + = new System.EventHandler(plc_hldr_Control_Init);


//将Init功能移动到Page_Init处理程序

Dyn_Control_Placeholder.Controls.Add

(新的LiteralControl(< br> ******在init ********<上添加1) ; br>< br>"));

}

/ * ------------------- ----------------------------------------------- * /

/ * ----------------------------------------- ------------------------- * /

< [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < ; [+]> - < [+]> - < [+]> - < [+]>

< [+]> - < [+ ]> - < [+]> - < [+]> - & LT; [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]>


...它按预期工作。

...所以问题什么都没有与附加的LiteralControl有关。

我希望比我更聪明的人可以在这上面告诉我

- 我将非常感激。


我的完整代码如下:

< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+ ]> - < [+]> - < [+]>

< [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < ; [+]> - < [+]> - < [+]>


<%@ Page Language =" C#" AutoEventWireup = QUOT;真" %>


< html>

< head>


< script runat ="服务器">


/ * -------------------------------- ---------------------------------- * /

/ * ---- -------------------------------------------------- ------------ * /


/ * - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -

* /

//受保护的类sys_obj_class

公共类sys_obj_class

{

private Page this_page01;

public Page Get_this_page01

{get {return this_page01; } $

私人PlaceHolder Obj_Dyn_Ctrl_Placeholder;

public PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder

{get {return Obj_Dyn_Ctrl_Placeholder; } $

private Label Obj_Dyn_Label01;

public Label Get_Obj_Dyn_Label01

{get {return Obj_Dyn_Label01; } $

public sys_obj_class

(PlaceHolder Dyn_Ctrl_Placeholder,Label Dyn_Label)

{

this_page01 = Dyn_Ctrl_Placeholder.Page;

Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;

Obj_Dyn_Label01 = Dyn_Label;

}

}


/ * -------------------------------------------- ---------------------- * /

/ * ---------------- -------------------------------------------------- * /

void plc_hldr_Control_Init(对象发件人,EventArgs e)

{

int ndx = 1;


// Dyn_Control_Placeholder.Controls.Add

this.Controls.Add

(新的LiteralControl(< br>在init< br>"上添加1) ));

}

/ * ---------------------------- -------------------------------------- * /

/ * -------------------------------------------------- ---------------- * /

void Page_Init(对象发件人,EventArgs e)

{

int ndx = 2;


//为''Init'添加事件处理程序。


Dyn_Control_Placeholder.Init

+ = new System.EventHandler(plc_hldr_Control_Init);

}

/ * -------------- -------------------------------------------------- - * /

/ * ------------------------------------ ------------------------------ * /

protected void Page_Load(Object sender,EventArgs e)

{

PlaceHolder plc_hldr =(PlaceHolder)FindControl

(" Dyn_Control_Placeholder");

标签lbl_msg01 = (标签)FindControl(" Message01");

sys_obj_class sys_obj = new sys_obj_class(plc_hldr,lbl_msg01);


ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01(sys_obj) ;


ccp1.create_ctrl_pair_01();

}

/ * ------------ -------------------------------------------------- ---- * /

/ * ---------------------------------- -------------- ------------------ * /


/ * - - - - - - - - - - - - - - - - - - - - - - * /

/ * - - - - - - - - - - - - - - - - - - - - - - * /

protected class base_create_ctrl_pair

{

protected TextBox UserTextBox0x;

protected Button button0x;

protected PlaceHolder CCP_Dyn_Ctrl_Placeholder;

protected Label Dyn_Lbl_msg01;


/ * =#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=

*

<<<构造函数>>>

* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=#=#=#=#=#=#=#=#=

* /

protected base_create_ctrl_pair( sys_obj_class sys_obj)

{

CCP_Dyn_Ctrl_Placeholder = sys_obj。

Get_Obj_Dyn_Ctrl_Placeholder;

Dyn_Lbl_msg01 = sys_obj.Get_Obj_Dyn_Label01;

}

/ * =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=

* /

/ * =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=

* /


私有TextBox create_text_box_control(String text_box_id)

{//创建UserTextBox TextBox控件。

TextBox new_TextBox = new TextBox();


//配置UserTextBox TextBox控件。

new_TextBox.ID = text_box_id;


//将UserTextBox TextBox控件添加到Controls集合

// Dyn_Control_Placeholder PlaceHolder控件。

CCP_Dyn_Ctr l_Placeholder.Controls.Add(new_TextBox);

CCP_Dyn_Ctrl_Placeholder.Controls.Add

(新的LiteralControl("< br>< br>"));


返回new_TextBox;

}


/ * ------------- -------------------------------------------- *

示例:以下示例创建一个Button,

将其DialogResult属性设置为DialogResult.OK,

并将其添加到表单。

* ----------------------------------------------- ---------- * /

private void Create_new_button(String Btn_ID,String Btn_text)

{//创建并初始化一个Button。

button0x = new Button();

button0x.ID = Btn_ID;

button0x.Text = Btn_text;


CCP_Dyn_Ctrl_Placeholder.Controls.Add(button0x);

CCP_Dyn_Ctrl_Placeholder.Controls.Add

(新的LiteralControl("< br> ======== ===========< br>< br>"));

}


pr otected void init_single_line_text_box(TextBox new_TextBox,int

col_sz)

{new_TextBox.Columns = col_sz; }


protected void create_ctrl_pair_0x

(String TB_ID,String DB_ID,String DB_txt)

{//创建UserTextBox TextBox控件。

UserTextBox0x = create_text_box_control(TB_ID);

Create_new_button(DB_ID,DB_txt);

}


/ * - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -

+ - *

<<<按钮单击处理程序>>>

* - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -

+ - * /

private String submit_click_str01 =" The TextBox";


private String submit_click_str02

="上面的控制是动态生成的。 <峰; br>您输入
:" ;;


public void Submit_Click(Object sender,EventArgs e)

{//检索UserTextBox来自

的TextBox控件Dyn_Control_Placeholder

// PlaceHolder控件。

TextBox TempTextBox =(TextBox)CCP_Dyn_Ctrl_Placeholder。

FindControl(" UserTextBox1");


//显示Text属性。

Dyn_Lbl_msg01.Text = submit_click_str01 +''1''+

submit_click_str02 + TempTextBox.Text;

}

/ * - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -

+ - * /

/ * - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -

+ - * /


}

/ * - - - - - - - - - - - - - - - - - - - - - - * /

/ * - - - - - - - - - - - - - - - - - - - - - - * /


protected class ctrl_pair_creation_01:base_create_ctrl_pair

{

private sys_obj_cl ass lcl_sys_obj;


//构造函数

public ctrl_pair_creation_01(sys_obj_class sys_obj):base

(sys_obj)

{lcl_sys_obj = sys_obj; }


/ *。 。 。 。 。 。 。 。 。 。 。 。 。 * /

public void create_ctrl_pair_01()

{create_ctrl_pair_0x

(" UserTextBox1"," DButton01"," Submit 01") ;


button0x.Click + = new EventHandler(Submit_Click);


if(!lcl_sys_obj.Get_this_page01.IsPostBack)

init_single_line_text_box(UserTextBox0x,22);

}

/ *。 。 。 。 。 。 。 。 。 。 。 。 。 * /

}

/ * - - - - - - - - - - - - - - - - - - - - - - * /

/ * - - - - - - - - - - - - - - - - - - - - - - * /

/ * - - - - - - - - - - - - - - - - - - - - - - * /


< / script>

< / head>

< body>


< form runat =" server">


< h3>控制初始化< / h3>


输入一些文本并单击提交按钮。 < br>< br>

< asp:PlaceHolder ID =" Dyn_Control_Placeholder" runat =" server" />


< asp:Label ID =" Message01" runat =" server" />


< / form>


< / body>

< / html>


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]>

< [+]> - < [+]> - < [+]> - < [+] > - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]>


感谢提前!!!

Wylbur

=======================

解决方案

尝试连接Init对于占位符,通过< asp:Placeholder OnInit =" YourEventHandler">

语法。


-Brock

DevelopMentor
http://staff.develop.com/ballen

大家好的天才,

我在试图获得一个问题一个Init处理程序,用于在初始化阶段触发
占位符
控件。我已将此问题发布到其他3个论坛上,
并且没有人愿意触摸它。
我试图将一个文字控件附加到占位符:


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < ; [+]



/ ------------------------ ------------------------------------------
* /
/ * ---------------------------------------------- --------------------
* /
void plc_hldr_Control_Init(object sender,EventArgs e)
{
int ndx = 1;
// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
(新的LiteralControl(< br>在init< br>"上添加1));
}
/ * ------------------------ ------------------------------------------
* /
/ * ---------------------------------------------- --------------------
* /
void Page_Init(对象发送者,EventArgs e)
{
int ndx = 2;
//为''Init'添加事件处理程序。

Dyn_Control_Placeholder.Init
+ = new System.EventHandler(plc_hldr_Control_Init);
}
/ * -------------------------------------------- ----------------------
* / / *
---------------- -------------------------------------------------- *

< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]



......没有任何反应:Init处理程序从未被解雇。
(plc_hldr_Control_Init),并且从未到达断点。

我已阅读SDK文档,并且我以为我弄清楚了:
< [+]> - < [+]> - < [+]> - < [+]> - < [+]> ; - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]


< [+]> - < [+]> - < [+]> - < [+] > - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]


.NET Framework类库
Control.Init事件[C#]

C#
公共事件EventHandler Init;
事件数据
事件处理程序接收类型为EventArgs的参数。
备注
服务器控件应执行任何初始化步骤这需要
来创建和设置实例。您不能在此活动中使用视图状态
信息;它还没有填充。在此活动期间,您不应该访问另一个服务器控件,无论它是该控件的子级
还是
父级。其他服务器控件不一定要创建
并准备好访问。
示例
[C#]以下示例分配自定义事件处理程序,
Control_Init,<当在包含控件的页面上调用Page_Init方法
时,控件myControl的Init事件发生。
void Page_Init(object sender,EventArgs e)
{
//为''Init'添加事件处理程序。
myControl.Init + = new System.EventHandler(Control_Init);
}
void Control_Init(对象sender,EventArgs e)
Response.Write("最初的对象的ID:" + myControl.ID);
//更改ID属性。
myControl.ID =" TestControl";
Response.Write("< br>已更改的ID:" + myControl.ID);
}
? 2001-2002微软公司。保留所有权利。

< [+]> - < [+]> - < [+]> - < [+]> - < [+]> ; - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]


< [+]> - < [+]> - < [+]> - < [+] > - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]



我不明白的一件事是:myControl在哪里?来自
给出的例子?

只是为了笑,我将Init功能移到了Page_Init
处理程序中:
< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]> - < [+]> - < [+]> - < [+]


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> [< [+]> - < [+]


/ * --------------------------------------- ---------------------------
* /
/ * ----------- -------------------------------------------------- -----
* /
public void plc_hldr_Control_Init(object sender,EventArgs e)
{n / x} = / / / / / / / / / / / / / / / / / / / / / / / / / /
this.Controls.Add
(新的LiteralControl(< br>在init< br>"上添加1));
}
/ * ---- ----------------------------------------------- ---------------
* /
/ * ----------------------- -------------------------------------------
* / <公共无效Page_Init(对象发送者,EventArgs e)
{n / n} =
//为初始化添加事件处理程序。

// Dyn_Control_Placeholder.Init
// + = new System.EventHandler(plc_hldr_Control_Init);
//将Init功能移动到Page_Init处理程序
Dyn_Control_Placeholder.Controls.Add
(新的LiteralControl(< br> ******在init上添加1
********< br>< br>"));
}
/ * -------------------------------------------- ----------------------
* / / *
---------------- -------------------------------------------------- * /
< [+]> - < [+]> - < [+]>< [+]> - < [+]> - < [+ ]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+] < blockquote class =post_quotes>


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+ ]> - < [+]



...它按预期工作。
...所以这个问题什么都没有与附加的LiteralControl有关。
我希望比我更聪明的人可以在这上面提醒我 - 我会非常感激。
我的完整代码如下:
< [+]> - < [+]> - < [+]> - < [+]>< [+]> [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+ ]


< [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - < [+]> - 百分比抑制率数据+]> - < [+]



<%@ Page Language =" C#" AutoEventWireup = QUOT;真" %>

< html> < head>

< script runat =" server">

/ * ----------------- -------------------------------------------------
* / / *
--------------------------------------- --------------------------- * /

/ *
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -
* /
//受保护的类sys_obj_class
公共类sys_obj_class
{
私人页面this_page01;
公共页面Get_this_page01
{get {return this_page01;私有PlaceHolder Obj_Dyn_Ctrl_Placeholder;
公共PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder
{get {return Obj_Dyn_Ctrl_Placeholder;私有标签Obj_Dyn_Label01;
公共标签Get_Obj_Dyn_Label01
{get {return Obj_Dyn_Label01;公共sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeholder,Label Dyn_Label)
{
this_page01 = Dyn_Ctrl_Placeholder.Page;
Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;
Obj_Dyn_Label01 = Dyn_Label;
}
}
/ * ---------------------------------- --------------------------------
* /
/ * ------ -------------------------------------------------- ----------
* /
void plc_hldr_Control_Init(对象发送者,EventArgs e)
{n / n = x;
// Dyn_Control_Placeholder .Controls.Add
this.Controls.Add
(新的LiteralControl(< br>在init< br>"上添加1));
}
/ * -------------------------------------------------- ----------------
* /
/ * ---------------------- --------------------------------------------
* /
void Page_Init(object sender,EventArgs e)
{n / n} =
//为''Init'添加事件处理程序。

Dyn_Control_Placeho lder.Init
+ = new System.EventHandler(plc_hldr_Control_Init);
}
/ * ---------------------- --------------------------------------------
* /
/ * -------------------------------------------- ----------------------
* /
protected void Page_Load(Object sender,EventArgs e)
{
PlaceHolder plc_hldr =(PlaceHolder)FindControl
(" Dyn_Control_Placeholder");
标签lbl_msg01 =(标签)FindControl(" Message01");
sys_obj_class sys_obj = new sys_obj_class(plc_hldr,
lbl_msg01);
ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01
(sys_obj);

ccp1.create_ctrl_pair_01();
}
/ * - -------------------------------------------------- --------------
* /
/ * ------------------------ ------------------------------------------
* /

/ * - - - - - - - - - - - - - - - - - - - - - * /
/ * - - - - - - - - - - - - - - - - - - - - - - * /
受保护的班级base_create_ctrl_pair
受保护的TextBox UserTextBox0x;
受保护的按钮button0x;
受保护的PlaceHolder CCP_Dyn_Ctrl_Placeholder;
受保护的标签Dyn_Lbl_msg01;
/ *
=# =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=
*
<<<构造函数>>>
*
=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=#=#=#=#=#=#=#=#=
* /
受保护的base_create_ctrl_pair(sys_obj_class sys_obj)
{
CCP_Dyn_Ctrl_Placeholder = sys_obj。
Get_Obj_Dyn_Ctrl_Placeholder;
Dyn_Lbl_msg01 = sys_obj.Get_Obj_Dyn_Label01;
}
/ *
=#=#=#=#=#= #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= #=
* /
/ *
=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
* /
私有TextBox create_text_box_control(String text_box_id)
{//创建UserTextBox TextBox控件。
TextBox new_TextBox = new TextBox();
//配置UserTextBox TextBox控件。
new_TextBox.ID = text_box_id;
//将UserTextBox TextBox控件添加到Dyn_Control_Placeholder PlaceHolder控件的控件
//。
CCP_Dyn_Ctrl_Placeholder.Controls.Add(new_TextBox);
CCP_Dyn_Ctrl_Placeholder.Controls.Add
(李新teralControl("< br>< br>"));
返回new_TextBox;
}
/ * --------------- ------------------------------------------
*
示例:以下示例创建一个Button,
将其DialogResult属性设置为DialogResult.OK,
并将其添加到表单。
* ----------- ----------------------------------------------
* /
private void Create_new_button(String Btn_ID,String
Btn_text)
{//创建并初始化一个Button。
button0x = new Button();
button0x。 ID = Btn_ID;
button0x.Text = Btn_text;
CCP_Dyn_Ctrl_Placeholder.Controls.Add(button0x);
CCP_Dyn_Ctrl_Placeholder.Controls.Add
(新的LiteralControl("< br> ===================< br>< br>")
);
}
protected void init_single_line_text_box(TextBox
new_TextBox,int
col_sz)
{new_TextBox.Columns = col_sz; }
protected void create_ctrl_pair_0x
(String TB_ID,String DB_ID,String DB_txt)
{//创建UserTextBox TextBox控件。
UserTextBox0x = create_text_box_control(TB_ID);
Create_new_button (DB_ID,DB_txt);
}
/ *
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -
+ - *
<<< ;按钮单击处理程序>>>
*
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -
+ - * /
私有字符串submit_click_str01 =" TextBox" ;;
private String submit_click_str02
="上面的控制是动态生成的。 < br>
您输入了:" ;;
public void Submit_Click(Object sender,EventArgs e)
{//从
中检索UserTextBox TextBox控件Dyn_Control_Placeholder
// PlaceHolder控件。
TextBox TempTextBox =(TextBox)CCP_Dyn_Ctrl_Placeholder。
FindControl(" UserTextBox1");
//显示Text属性。
Dyn_Lbl_msg01 .Text = submit_click_str01 +''1''+
submit_click_str02 + TempTextBox.Text;
}
/ *
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -
+ - * /
/ *
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creation_01 : base_create_ctrl_pair
{
private sys_obj_class lcl_sys_obj;
// constructor
public ctrl_pair_creation_01 (sys_obj_class sys_obj) : base
(sys_obj)
{ lcl_sys_obj = sys_obj; }
/* . 。 。 。 。 。 。 。 。 。 。 。 。 */
public void create_ctrl_pair_01 ()
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");
button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.Get_this_page01.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);
}
/* . 。 。 。 。 。 。 。 。 。 。 。 。 */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
</script>
</head>
<body>

<form runat="server">

<h3> Control Init </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolder ID="Dyn_Control_Placeholder" runat="server"/>

<asp:Label ID="Message01" runat="server"/>

</form>

</body>
</html>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



THANKS IN ADVANCE!!!

Wylbur
=======================




Hi Brock,


I did that, and it worked: I got the Init function to fire.


OK - so now I need to figure out why I can’’t get it to work from the

Page_Init method.


I hope you have an idea.

Thanks,


Wylbur

============================


Brock Allen wrote:Try wiring up the Init for the Placeholder via the <asp:Placeholder OnInit="YourEventHandler">
syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Hello to all of you geniuses,


[quoted text clipped - 370 lines]

Wylbur
=======================



--

Message posted via http://www.dotnetmonster.com


Because Child controls’’ Init is called before the parent control’’s Init (in

this case, the page).


-Brock

DevelopMentor
http://staff.develop.com/ballen

Hi Brock,

I did that, and it worked: I got the Init function to fire.

OK - so now I need to figure out why I can’’t get it to work from the
Page_Init method.

I hope you have an idea.

Thanks,

Wylbur
============================
Brock Allen wrote:

Try wiring up the Init for the Placeholder via the <asp:Placeholder
OnInit="YourEventHandler"> syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Hello to all of you geniuses,


[quoted text clipped - 370 lines]

Wylbur
=======================




Hello to all of you geniuses,

I''m having a problem trying to get an Init handler to fire for a Placeholder
control
at the initialization phase. I?ve posted this problem to 3 other ASP.NET
forums,
and noone wants to touch it.

I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Control_Init (object sender, EventArgs e)
{
int ndx = 1;

// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
( new LiteralControl ("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init (object sender, EventArgs e)
{
int ndx = 2;

// Add a event Handler for ''Init''.

Dyn_Control_Placeholder.Init
+= new System.EventHandler (plc_hldr_Control_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ *

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

... and nothing happened: The Init handler never fired.

I put my code in the debugger, set a breakpoint on the Init handler
(plc_hldr_Control_Init), and the breakpoint was never reached.

I''ve read the SDK docs, and I thought I had it figured out:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
.NET Framework Class Library

Control.Init Event [C#]

C#
public event EventHandler Init;

Event Data
The event handler receives an argument of type EventArgs.

Remarks
Server controls should perform any initialization steps that are required
to create and set up an instance. You cannot use view-state information
within this event; it is not populated yet. You should not access another
server control during this event, regardless of whether it is a child or
parent to this control. Other server controls are not certain to be created
and ready for access.

Example
[C#] The following example assigns a custom event handler, Control_Init,
to the Init event of a control, myControl, when the Page_Init method is
called on the page that contains the control.

void Page_Init(object sender,EventArgs e)
{
// Add a event Handler for ''Init''.
myControl.Init += new System.EventHandler(Control_Init);
}

void Control_Init(object sender,EventArgs e)
{
Response.Write("The ID of the object initially : " + myControl.ID);
// Change the ID property.
myControl.ID="TestControl";
Response.Write("<br>The changed ID : " + myControl.ID);
}

? 2001-2002 Microsoft Corporation. All rights reserved.

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

One thing I don''t understand is: Where did "myControl" come from in the
given example?

Just for laughs, I moved the Init functionality into the Page_Init handler:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
public void plc_hldr_Control_Init (object sender, EventArgs e)
{
int ndx = 1;

// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
( new LiteralControl("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
public void Page_Init (object sender, EventArgs e)
{
int ndx = 2;

// Add a event Handler for ''Init''.

// Dyn_Control_Placeholder.Init
// += new System.EventHandler (plc_hldr_Control_Init);

// Moving the Init functionality to the Page_Init handler
Dyn_Control_Placeholder.Controls.Add
( new LiteralControl("<br>****** added 1 on init ********<br><br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

... and it worked as expected.
... so the problem has nothing to do with the LiteralControl being attached.
I''m hoping that someone smarter than me can clue me in on this
- I would be most grateful.

My complete code is as follows:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

<script runat="server">

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
*/
// protected class sys_obj_class
public class sys_obj_class
{
private Page this_page01;
public Page Get_this_page01
{ get { return this_page01; } }

private PlaceHolder Obj_Dyn_Ctrl_Placeholder;
public PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder
{ get { return Obj_Dyn_Ctrl_Placeholder; } }

private Label Obj_Dyn_Label01;
public Label Get_Obj_Dyn_Label01
{ get { return Obj_Dyn_Label01; } }
public sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeholder, Label Dyn_Label)
{
this_page01 = Dyn_Ctrl_Placeholder.Page;
Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;
Obj_Dyn_Label01 = Dyn_Label;
}
}

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Control_Init (object sender, EventArgs e)
{
int ndx = 1;

// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
( new LiteralControl("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init (object sender, EventArgs e)
{
int ndx = 2;

// Add a event Handler for ''Init''.

Dyn_Control_Placeholder.Init
+= new System.EventHandler (plc_hldr_Control_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load (Object sender, EventArgs e)
{
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_Placeholder");
Label lbl_msg01 = (Label) FindControl ("Message01");
sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);

ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01 (sys_obj);

ccp1.create_ctrl_pair_01 ();
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class base_create_ctrl_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected PlaceHolder CCP_Dyn_Ctrl_Placeholder;
protected Label Dyn_Lbl_msg01;

/* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*
<<< constructor >>>
* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*/
protected base_create_ctrl_pair (sys_obj_class sys_obj)
{
CCP_Dyn_Ctrl_Placeholder = sys_obj.
Get_Obj_Dyn_Ctrl_Placeholder;
Dyn_Lbl_msg01 = sys_obj.Get_Obj_Dyn_Label01;
}
/* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*/
/* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*/

private TextBox create_text_box_control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();

// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;

// Add UserTextBox TextBox control to the Controls collection
// of the Dyn_Control_Placeholder PlaceHolder control.
CCP_Dyn_Ctrl_Placeholder.Controls.Add (new_TextBox);
CCP_Dyn_Ctrl_Placeholder.Controls.Add
( new LiteralControl("<br><br>") );

return new_TextBox;
}

/* --------------------------------------------------------- *
Example: The following example creates a Button,
sets its DialogResult property to DialogResult.OK,
and adds it to a Form.
* --------------------------------------------------------- */
private void Create_new_button (String Btn_ID, String Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
button0x.ID = Btn_ID;
button0x.Text = Btn_text;

CCP_Dyn_Ctrl_Placeholder.Controls.Add (button0x);
CCP_Dyn_Ctrl_Placeholder.Controls.Add
( new LiteralControl("<br>===================<br><br>") );
}

protected void init_single_line_text_box (TextBox new_TextBox, int
col_sz)
{ new_TextBox.Columns = col_sz; }

protected void create_ctrl_pair_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box_control (TB_ID);
Create_new_button(DB_ID, DB_txt);
}

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- *
<<< Button Click Handlers >>>
* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */
private String submit_click_str01 = "The TextBox";

private String submit_click_str02
= " control above is dynamically generated. <br> You
entered: ";

public void Submit_Click (Object sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the
Dyn_Control_Placeholder
// PlaceHolder control.
TextBox TempTextBox = (TextBox) CCP_Dyn_Ctrl_Placeholder.
FindControl("UserTextBox1");

// Display the Text property.
Dyn_Lbl_msg01.Text = submit_click_str01 + ''1'' +
submit_click_str02 + TempTextBox.Text;
}
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */

}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

protected class ctrl_pair_creation_01 : base_create_ctrl_pair
{
private sys_obj_class lcl_sys_obj;

// constructor
public ctrl_pair_creation_01 (sys_obj_class sys_obj) : base
(sys_obj)
{ lcl_sys_obj = sys_obj; }

/* . . . . . . . . . . . . . */
public void create_ctrl_pair_01 ()
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.Get_this_page01.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

</script>
</head>

<body>

<form runat="server">

<h3> Control Init </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolder ID="Dyn_Control_Placeholder" runat="server"/>

<asp:Label ID="Message01" runat="server"/>

</form>

</body>
</html>

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

THANKS IN ADVANCE!!!
Wylbur
=======================

解决方案

Try wiring up the Init for the Placeholder via the <asp:Placeholder OnInit="YourEventHandler">
syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Hello to all of you geniuses,

I''m having a problem trying to get an Init handler to fire for a
Placeholder
control
at the initialization phase. I?ve posted this problem to 3 other
ASP.NET
forums,
and noone wants to touch it.
I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
void plc_hldr_Control_Init (object sender, EventArgs e)
{
int ndx = 1;
// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
( new LiteralControl ("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
void Page_Init (object sender, EventArgs e)
{
int ndx = 2;
// Add a event Handler for ''Init''.

Dyn_Control_Placeholder.Init
+= new System.EventHandler (plc_hldr_Control_Init);
}
/* ------------------------------------------------------------------
*/ /*
------------------------------------------------------------------ *

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



... and nothing happened: The Init handler never fired.

I put my code in the debugger, set a breakpoint on the Init handler
(plc_hldr_Control_Init), and the breakpoint was never reached.

I''ve read the SDK docs, and I thought I had it figured out:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


.NET Framework Class Library
Control.Init Event [C#]

C#
public event EventHandler Init;
Event Data
The event handler receives an argument of type EventArgs.
Remarks
Server controls should perform any initialization steps that are
required
to create and set up an instance. You cannot use view-state
information
within this event; it is not populated yet. You should not access
another
server control during this event, regardless of whether it is a child
or
parent to this control. Other server controls are not certain to be
created
and ready for access.
Example
[C#] The following example assigns a custom event handler,
Control_Init,
to the Init event of a control, myControl, when the Page_Init method
is
called on the page that contains the control.
void Page_Init(object sender,EventArgs e)
{
// Add a event Handler for ''Init''.
myControl.Init += new System.EventHandler(Control_Init);
}
void Control_Init(object sender,EventArgs e)
{
Response.Write("The ID of the object initially : " + myControl.ID);
// Change the ID property.
myControl.ID="TestControl";
Response.Write("<br>The changed ID : " + myControl.ID);
}
? 2001-2002 Microsoft Corporation. All rights reserved.

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



One thing I don''t understand is: Where did "myControl" come from in
the given example?

Just for laughs, I moved the Init functionality into the Page_Init
handler:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
public void plc_hldr_Control_Init (object sender, EventArgs e)
{
int ndx = 1;
// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
( new LiteralControl("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
public void Page_Init (object sender, EventArgs e)
{
int ndx = 2;
// Add a event Handler for ''Init''.

// Dyn_Control_Placeholder.Init
// += new System.EventHandler (plc_hldr_Control_Init);
// Moving the Init functionality to the Page_Init handler
Dyn_Control_Placeholder.Controls.Add
( new LiteralControl("<br>****** added 1 on init
********<br><br>") );
}
/* ------------------------------------------------------------------
*/ /*
------------------------------------------------------------------ */
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



... and it worked as expected.
... so the problem has nothing to do with the LiteralControl being
attached.
I''m hoping that someone smarter than me can clue me in on this
- I would be most grateful.
My complete code is as follows:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



<%@ Page Language="C#" AutoEventWireup="True" %>

<html> <head>

<script runat="server">

/* ------------------------------------------------------------------
*/ /*
------------------------------------------------------------------ */

/*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
*/
// protected class sys_obj_class
public class sys_obj_class
{
private Page this_page01;
public Page Get_this_page01
{ get { return this_page01; } }
private PlaceHolder Obj_Dyn_Ctrl_Placeholder;
public PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder
{ get { return Obj_Dyn_Ctrl_Placeholder; } }
private Label Obj_Dyn_Label01;
public Label Get_Obj_Dyn_Label01
{ get { return Obj_Dyn_Label01; } }
public sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeholder, Label Dyn_Label)
{
this_page01 = Dyn_Ctrl_Placeholder.Page;
Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;
Obj_Dyn_Label01 = Dyn_Label;
}
}
/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
void plc_hldr_Control_Init (object sender, EventArgs e)
{
int ndx = 1;
// Dyn_Control_Placeholder.Controls.Add
this.Controls.Add
( new LiteralControl("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
void Page_Init (object sender, EventArgs e)
{
int ndx = 2;
// Add a event Handler for ''Init''.

Dyn_Control_Placeholder.Init
+= new System.EventHandler (plc_hldr_Control_Init);
}
/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/
protected void Page_Load (Object sender, EventArgs e)
{
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_Placeholder");
Label lbl_msg01 = (Label) FindControl ("Message01");
sys_obj_class sys_obj = new sys_obj_class (plc_hldr,
lbl_msg01);
ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01
(sys_obj);

ccp1.create_ctrl_pair_01 ();
}
/* ------------------------------------------------------------------
*/
/* ------------------------------------------------------------------
*/

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class base_create_ctrl_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected PlaceHolder CCP_Dyn_Ctrl_Placeholder;
protected Label Dyn_Lbl_msg01;
/*
=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*
<<< constructor >>>
*
=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*/
protected base_create_ctrl_pair (sys_obj_class sys_obj)
{
CCP_Dyn_Ctrl_Placeholder = sys_obj.
Get_Obj_Dyn_Ctrl_Placeholder;
Dyn_Lbl_msg01 = sys_obj.Get_Obj_Dyn_Label01;
}
/*
=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*/
/*
=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# =#=#=#=#=#=#=
*/
private TextBox create_text_box_control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();
// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;
// Add UserTextBox TextBox control to the Controls
collection
// of the Dyn_Control_Placeholder PlaceHolder control.
CCP_Dyn_Ctrl_Placeholder.Controls.Add (new_TextBox);
CCP_Dyn_Ctrl_Placeholder.Controls.Add
( new LiteralControl("<br><br>") );
return new_TextBox;
}
/* ---------------------------------------------------------
*
Example: The following example creates a Button,
sets its DialogResult property to DialogResult.OK,
and adds it to a Form.
* ---------------------------------------------------------
*/
private void Create_new_button (String Btn_ID, String
Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
button0x.ID = Btn_ID;
button0x.Text = Btn_text;
CCP_Dyn_Ctrl_Placeholder.Controls.Add (button0x);
CCP_Dyn_Ctrl_Placeholder.Controls.Add
( new LiteralControl("<br>===================<br><br>")
);
}
protected void init_single_line_text_box (TextBox
new_TextBox, int
col_sz)
{ new_TextBox.Columns = col_sz; }
protected void create_ctrl_pair_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box_control (TB_ID);
Create_new_button(DB_ID, DB_txt);
}
/*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- *
<<< Button Click Handlers >>>
*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */
private String submit_click_str01 = "The TextBox";
private String submit_click_str02
= " control above is dynamically generated. <br>
You
entered: ";
public void Submit_Click (Object sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the
Dyn_Control_Placeholder
// PlaceHolder control.
TextBox TempTextBox = (TextBox) CCP_Dyn_Ctrl_Placeholder.
FindControl("UserTextBox1");
// Display the Text property.
Dyn_Lbl_msg01.Text = submit_click_str01 + ''1'' +
submit_click_str02 + TempTextBox.Text;
}
/*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */
/*
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+- */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creation_01 : base_create_ctrl_pair
{
private sys_obj_class lcl_sys_obj;
// constructor
public ctrl_pair_creation_01 (sys_obj_class sys_obj) : base
(sys_obj)
{ lcl_sys_obj = sys_obj; }
/* . . . . . . . . . . . . . */
public void create_ctrl_pair_01 ()
{ create_ctrl_pair_0x
("UserTextBox1", "DButton01", "Submit 01");
button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.Get_this_page01.IsPostBack)
init_single_line_text_box (UserTextBox0x, 22);
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
</script>
</head>
<body>

<form runat="server">

<h3> Control Init </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolder ID="Dyn_Control_Placeholder" runat="server"/>

<asp:Label ID="Message01" runat="server"/>

</form>

</body>
</html>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]


<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]



THANKS IN ADVANCE!!!

Wylbur
=======================




Hi Brock,

I did that, and it worked: I got the Init function to fire.

OK - so now I need to figure out why I can''t get it to work from the
Page_Init method.

I hope you have an idea.
Thanks,

Wylbur
============================

Brock Allen wrote:

Try wiring up the Init for the Placeholder via the <asp:Placeholder OnInit="YourEventHandler">
syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Hello to all of you geniuses,


[quoted text clipped - 370 lines]

Wylbur
=======================


--
Message posted via http://www.dotnetmonster.com


Because Child controls'' Init is called before the parent control''s Init (in
this case, the page).

-Brock
DevelopMentor
http://staff.develop.com/ballen

Hi Brock,

I did that, and it worked: I got the Init function to fire.

OK - so now I need to figure out why I can''t get it to work from the
Page_Init method.

I hope you have an idea.

Thanks,

Wylbur
============================
Brock Allen wrote:

Try wiring up the Init for the Placeholder via the <asp:Placeholder
OnInit="YourEventHandler"> syntax.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Hello to all of you geniuses,


[quoted text clipped - 370 lines]

Wylbur
=======================




这篇关于在Page_Init之后,初始处理程序未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆