复合控件... Microsoft Press:Dev ASP.NET Server Controls [英] composite controls... Microsoft Press: Dev ASP.NET Server Controls

查看:56
本文介绍了复合控件... Microsoft Press:Dev ASP.NET Server Controls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Microsoft Press:开发Microsoft ASP.NET服务器控件和

组件书。它开始对控制开发有所启发

但是有一些关于复合控制的东西,我不明白...

我已经包含了下面第12章关于复合控件的一个片段:


< start>


重写CreateChildControls方法以实例化子控件,

初始化它们,并将它们添加到控制树中。不要在构造函数或OnInit方法中执行此逻辑




让我们检查一下这个实现细节的原因。您必须在CreateChildControls方法中创建

您的子控件 - 而不是在特定阶段(例如Instantiate或Initialize)创建

- 以便孩子们
可以在控件的生命周期中根据需要创建
。这是

特别重要的是当你创建复合控件时,其子控件

处理回发数据。


< end>


我根本不明白这一点。在我看来,Init方法将是一个初始化子对象的安全场所,因为该方法在加载回发数据或引发回发事件之前发生了
(在控件中)生活

周期。)我在这里缺少什么?


非常感谢提前。


Stan

I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and
Components book. It''s starting to shine some light on control development
but there is something about composite controls that I don''t understand...
I''ve included a snippet from Chapter 12 below on Composite Controls:

<start>

Override the CreateChildControls method to instantiate child controls,
initialize them, and add them to the control tree. Do not perform this logic
in the constructor or in the OnInit method.

Let''s examine the reason for this implementation detail. You must create
your child controls in the CreateChildControls method--instead of creating
them in a specific phase such as Instantiate or Initialize--so that children
can be created on demand when needed in your control''s life cycle. This is
especially important when you create composite controls whose child controls
handle postback data.

<end>

I do not understand this at all. It seems to me that the Init method would
be a safe place to initialize the child objects since that method occurs
before loading postback data or raising postback events (in the control life
cycle.) What am I missing here?

Much Thanks in advance.

Stan

推荐答案

" dx" <德********* @ yahoo.com>在消息中写道

news:x6 ******************** @ giganews.com ...
"dx" <de*********@yahoo.com> wrote in message
news:x6********************@giganews.com...
I有Microsoft Press:开发Microsoft ASP.NET服务器控件
和组件预订。它开始对控制开发有所启发
但复合控件有一些我不明白的东西......
我已经在下面的第12章中介绍了复合材料的一些片段控件:

< start>

重写CreateChildControls方法以实例化子控件,初始化它们,并将它们添加到控件树中。不要在构造函数或OnInit方法中执行这个
逻辑。

让我们检查一下这个实现细节的原因。您必须在CreateChildControls方法中创建您的子控件 - 而不是在特定阶段(例如Instantiate或Initialize)创建它们,以便在需要时可以按需创建
子项。你的控制的生命周期。当你创建其子
控件处理回发数据的复合控件时,这一点尤其重要。

< end>

我不明白这一点所有。在我看来,Init方法将是一个初始化子对象的安全位置,因为该方法在加载回发数据或引发回发事件之前发生(在控制
生命周期中)。我在这里缺少什么?
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It''s starting to shine some light on control development
but there is something about composite controls that I don''t understand...
I''ve included a snippet from Chapter 12 below on Composite Controls:

<start>

Override the CreateChildControls method to instantiate child controls,
initialize them, and add them to the control tree. Do not perform this logic in the constructor or in the OnInit method.

Let''s examine the reason for this implementation detail. You must create
your child controls in the CreateChildControls method--instead of creating
them in a specific phase such as Instantiate or Initialize--so that children can be created on demand when needed in your control''s life cycle. This is
especially important when you create composite controls whose child controls handle postback data.

<end>

I do not understand this at all. It seems to me that the Init method would
be a safe place to initialize the child objects since that method occurs
before loading postback data or raising postback events (in the control life cycle.) What am I missing here?




为什么你认为你_want_初始化Init

事件中的子对象?


子控件应该在需要时实例化,而不是之前。

你可能在Init事件中不需要它们。

-

John Saunders

SurfControl.com的John.Saunders



Why do you think you _want_ to initialize the child objects in the Init
event?

Child controls should be instantiated when they are needed, and not before.
You probably don''t need them up in the Init event.
--
John Saunders
John.Saunders at SurfControl.com


" DX" <德********* @ yahoo.com>在消息中写道

news:x6 ******************** @ giganews.com ...
"dx" <de*********@yahoo.com> wrote in message
news:x6********************@giganews.com...
I有Microsoft Press:开发Microsoft ASP.NET服务器控件
和组件预订。它开始对控制开发有所启发
但复合控件有一些我不明白的东西......
我已经在下面的第12章中介绍了复合材料的一些片段控件:

< start>

重写CreateChildControls方法以实例化子控件,初始化它们,并将它们添加到控件树中。不要在构造函数或OnInit方法中执行这个
逻辑。

让我们检查一下这个实现细节的原因。您必须在CreateChildControls方法中创建您的子控件 - 而不是在特定阶段(例如Instantiate或Initialize)创建它们,以便在需要时可以按需创建
子项。你的控制的生命周期。当你创建其子
控件处理回发数据的复合控件时,这一点尤其重要。

< end>

我不明白这一点所有。在我看来,Init方法将是一个初始化子对象的安全位置,因为该方法在加载回发数据或引发回发事件之前发生(在控制
生命周期中)。我在这里缺少什么?
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It''s starting to shine some light on control development
but there is something about composite controls that I don''t understand...
I''ve included a snippet from Chapter 12 below on Composite Controls:

<start>

Override the CreateChildControls method to instantiate child controls,
initialize them, and add them to the control tree. Do not perform this logic in the constructor or in the OnInit method.

Let''s examine the reason for this implementation detail. You must create
your child controls in the CreateChildControls method--instead of creating
them in a specific phase such as Instantiate or Initialize--so that children can be created on demand when needed in your control''s life cycle. This is
especially important when you create composite controls whose child controls handle postback data.

<end>

I do not understand this at all. It seems to me that the Init method would
be a safe place to initialize the child objects since that method occurs
before loading postback data or raising postback events (in the control life cycle.) What am I missing here?




为什么你认为你_want_初始化Init

事件中的子对象?


子控件应该在需要时实例化,而不是之前。

你可能在Init事件中不需要它们。

-

John Saunders

SurfControl.com的John.Saunders



Why do you think you _want_ to initialize the child objects in the Init
event?

Child controls should be instantiated when they are needed, and not before.
You probably don''t need them up in the Init event.
--
John Saunders
John.Saunders at SurfControl.com


我'我们经常想知道同样的事情 - 有些人根本没有使用CreateChildControl来打扰
- 请参阅
http://www.wilsondotnet.com/Tips/Vie...spx?Thread=278


可能它在cas中唯一有用e,孩子控制改变为回发的结果(例如,b / b)在一个简单的服务器端扩展一个节点

treeview控件) - 然后,你可以设置ChildControlsCreated = false到

重新创建它们(下次调用EnsureChildControls时)。 )。


乍一看我不能完全看出为什么这对你来说特别重要

创建复合控件,其子控件处理回发数据。

据推测,为了获得viewstate和回发数据,你需要

来确保在OnInit中调用EnsureChildControls - 所以为什么可以'' t

你只需在OnInit中创建它们。


也许更多的是迷你设计模式类型的东西 - 也许是

ASP.NET设计者认为其子控件保持静态的控件

(即控件集合中的实际对象不需要根据某些回发事件更改

或者价值)作为一个特例,一般情况下更多的是b $ b每个回发的控件集合可能会有所不同。所以

他们可能认为这最好由一个单独的函数处理

CreateChildControls,而不是直接在OnInit编码,所以试图

强制执行此操作作为最佳实践。


这是一个非常有趣的问题!

干杯,

Pete Beech

dx <德********* @ yahoo.com>在消息中写道

news:x6 ******************** @ giganews.com ...
I''ve often wondered the same - and there are some people who don''t bother
with CreateChildControls at all - see
http://www.wilsondotnet.com/Tips/Vie...spx?Thread=278 .

Possibly its only useful in the case that the child controls change as a
result of the postback (e.g. the expanding of a node in a simple serverside
treeview control) - then, you can just set ChildControlsCreated = false to
get them recreated (the next time EnsureChildControls is called.).

I can''t quite see at first glance why "this is especially important when you
create composite controls whose child controls handle postback data.".
Presumably, to get viewstate loaded, and postback data also, you would need
to make sure EnsureChildControls was called in OnInit anyway - so why can''t
you just create them in OnInit.

Maybe its more of a mini design pattern type thing - i.e., perhaps the
ASP.NET designers considered a control whose child controls remain static
(i.e. the actual objects in the Controls collection don''t need to change
based on some postback event or value) as a special case, and the more
general case is that the Controls collection could vary on each postback. So
they might have thought this is best handled by a separate function
CreateChildControls, rather than coding directly in OnInit, and so tried to
enforce this as a best practice.

Its a very interesting question!
Cheers,
Pete Beech
"dx" <de*********@yahoo.com> wrote in message
news:x6********************@giganews.com...
I有Microsoft Press:开发Microsoft ASP.NET服务器控件
和组件预订。它开始对控制开发有所启发
但复合控件有一些我不明白的东西......
我已经在下面的第12章中介绍了复合材料的一些片段控件:

< start>

重写CreateChildControls方法以实例化子控件,初始化它们,并将它们添加到控件树中。不要在构造函数或OnInit方法中执行这个
逻辑。

让我们检查一下这个实现细节的原因。您必须在CreateChildControls方法中创建您的子控件 - 而不是在特定阶段(例如Instantiate或Initialize)创建它们,以便在需要时可以按需创建
子项。你的控制的生命周期。当你创建其子
控件处理回发数据的复合控件时,这一点尤其重要。

< end>

我不明白这一点所有。在我看来,Init方法将是一个初始化子对象的安全位置,因为该方法在加载回发数据或引发回发事件之前发生(在控制
生命周期中)。我在这里错过了什么?

非常感谢提前。

Stan
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It''s starting to shine some light on control development
but there is something about composite controls that I don''t understand...
I''ve included a snippet from Chapter 12 below on Composite Controls:

<start>

Override the CreateChildControls method to instantiate child controls,
initialize them, and add them to the control tree. Do not perform this logic in the constructor or in the OnInit method.

Let''s examine the reason for this implementation detail. You must create
your child controls in the CreateChildControls method--instead of creating
them in a specific phase such as Instantiate or Initialize--so that children can be created on demand when needed in your control''s life cycle. This is
especially important when you create composite controls whose child controls handle postback data.

<end>

I do not understand this at all. It seems to me that the Init method would
be a safe place to initialize the child objects since that method occurs
before loading postback data or raising postback events (in the control life cycle.) What am I missing here?

Much Thanks in advance.

Stan



这篇关于复合控件... Microsoft Press:Dev ASP.NET Server Controls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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