开发者

Difference between form1.controls.add() and page.controls.add() in asp.net

Many times i have seen this cod开发者_Python百科e

Form1.controls.add()

and sometimes it is

Page.Controls.add()

What is the difference and when should they be used.

I am asking in context of a normal asp.net page without any master page. Content pages doesnot have Form1.controls.add().


Any asp.net web-control will give you a method to add controls inside since html is a nested markup language. In this particular case, Page contains Form1 control.

If you call,

Forms.controls.Add()

The control hierarchy after adding the control would be..

Page --> Form1 --> YourNewlAddedControl.

If you call,

Page.controls.Add()

The control hierarchy after adding the control would be..

Page --> Form1
Page --> YourNewlAddedControl.


Form is child control of Page

Form1.controls.add() added control like this

<Page>
   <Form>
       <MyControl/>
   </Form>
</Page>

Page.Controls.add() added control like this

<Page>
   <Form/>
   <MyControl/>
</Page>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜