Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Web UserControl inheritance

Reply
Thread Tools

Web UserControl inheritance

 
 
Ivan A. Vasilyev
Guest
Posts: n/a
 
      06-21-2007
Hello.

Could anyone please clarify one thing.

Suppose I have to classes:
1. A inherits UserControl
2. B inherits A

BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.

Then suppose I want to instantiate control B. I have three options:
1. Propgrammatically instatiate B through new B();
2. Propgrammatically instatiate B through LoadControl("B.ascx");
3. Declare control B in ASPX/ASCX of a container and refer B in code-behind
file of a container.

The quiestion is the following: Which of instantiation options are correct
to use?

I've tried (3) but it seems that html markup (in ASCX) of class A isn't
being parsed, so those children of A (from ASCX) are not being created.

TIA


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      06-24-2007
Hi,

ascx files aren't in the inheritance chain (assuming if I understand your
scenario correctly). If you put B to derive from A, it means B derives from
code-behind class of A, not the A.ascx being parsed through normal ASP.NET's
mechanisms (it is parsed dynamically or via Page.ParseControl/LoadControl
etc)

I think master pages would be closer solution to this.


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Ivan A. Vasilyev" <> wrote in message
news:...
> Hello.
>
> Could anyone please clarify one thing.
>
> Suppose I have to classes:
> 1. A inherits UserControl
> 2. B inherits A
>
> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
>
> Then suppose I want to instantiate control B. I have three options:
> 1. Propgrammatically instatiate B through new B();
> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
> 3. Declare control B in ASPX/ASCX of a container and refer B in
> code-behind file of a container.
>
> The quiestion is the following: Which of instantiation options are correct
> to use?
>
> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
> being parsed, so those children of A (from ASCX) are not being created.
>
> TIA
>



 
Reply With Quote
 
 
 
 
Ivan A. Vasilyev
Guest
Posts: n/a
 
      06-25-2007
Hello

Thanx for the answer.
I need to extend some ascx-based user control. So i think composition
(insted of inheritance) is the only way to go.

"Teemu Keiski" <> сообщил/сообщила в новостях
следующее: news:%...
> Hi,
>
> ascx files aren't in the inheritance chain (assuming if I understand your
> scenario correctly). If you put B to derive from A, it means B derives
> from code-behind class of A, not the A.ascx being parsed through normal
> ASP.NET's mechanisms (it is parsed dynamically or via
> Page.ParseControl/LoadControl etc)
>
> I think master pages would be closer solution to this.
>
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
> "Ivan A. Vasilyev" <> wrote in message
> news:...
>> Hello.
>>
>> Could anyone please clarify one thing.
>>
>> Suppose I have to classes:
>> 1. A inherits UserControl
>> 2. B inherits A
>>
>> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
>>
>> Then suppose I want to instantiate control B. I have three options:
>> 1. Propgrammatically instatiate B through new B();
>> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
>> 3. Declare control B in ASPX/ASCX of a container and refer B in
>> code-behind file of a container.
>>
>> The quiestion is the following: Which of instantiation options are
>> correct to use?
>>
>> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
>> being parsed, so those children of A (from ASCX) are not being created.
>>
>> TIA
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      06-29-2007
Sorry for delay, one way also is to put the layout/controls of the parent UC
to be created in code. That way it is inherited.


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Ivan A. Vasilyev" <> wrote in message
news:...
> Hello
>
> Thanx for the answer.
> I need to extend some ascx-based user control. So i think composition
> (insted of inheritance) is the only way to go.
>
> "Teemu Keiski" <> сообщил/сообщила в новостях
> следующее: news:%...
>> Hi,
>>
>> ascx files aren't in the inheritance chain (assuming if I understand your
>> scenario correctly). If you put B to derive from A, it means B derives
>> from code-behind class of A, not the A.ascx being parsed through normal
>> ASP.NET's mechanisms (it is parsed dynamically or via
>> Page.ParseControl/LoadControl etc)
>>
>> I think master pages would be closer solution to this.
>>
>>
>> --
>> Teemu Keiski
>> AspInsider, ASP.NET MVP
>> http://blogs.aspadvice.com/joteke
>> http://teemukeiski.net
>>
>> "Ivan A. Vasilyev" <> wrote in message
>> news:...
>>> Hello.
>>>
>>> Could anyone please clarify one thing.
>>>
>>> Suppose I have to classes:
>>> 1. A inherits UserControl
>>> 2. B inherits A
>>>
>>> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
>>>
>>> Then suppose I want to instantiate control B. I have three options:
>>> 1. Propgrammatically instatiate B through new B();
>>> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
>>> 3. Declare control B in ASPX/ASCX of a container and refer B in
>>> code-behind file of a container.
>>>
>>> The quiestion is the following: Which of instantiation options are
>>> correct to use?
>>>
>>> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
>>> being parsed, so those children of A (from ASCX) are not being created.
>>>
>>> TIA
>>>

>>
>>

>
>



 
Reply With Quote
 
Ivan A. Vasilyev
Guest
Posts: n/a
 
      07-02-2007
I have to avoid changing parent user control. But thanx anyway WBR.


"Teemu Keiski" <> сообщил/сообщила в новостях
следующее: news:...
> Sorry for delay, one way also is to put the layout/controls of the parent
> UC to be created in code. That way it is inherited.
>
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
> "Ivan A. Vasilyev" <> wrote in message
> news:...
>> Hello
>>
>> Thanx for the answer.
>> I need to extend some ascx-based user control. So i think composition
>> (insted of inheritance) is the only way to go.
>>
>> "Teemu Keiski" <> сообщил/сообщила в новостях
>> следующее: news:%...
>>> Hi,
>>>
>>> ascx files aren't in the inheritance chain (assuming if I understand
>>> your scenario correctly). If you put B to derive from A, it means B
>>> derives from code-behind class of A, not the A.ascx being parsed through
>>> normal ASP.NET's mechanisms (it is parsed dynamically or via
>>> Page.ParseControl/LoadControl etc)
>>>
>>> I think master pages would be closer solution to this.
>>>
>>>
>>> --
>>> Teemu Keiski
>>> AspInsider, ASP.NET MVP
>>> http://blogs.aspadvice.com/joteke
>>> http://teemukeiski.net
>>>
>>> "Ivan A. Vasilyev" <> wrote in message
>>> news:...
>>>> Hello.
>>>>
>>>> Could anyone please clarify one thing.
>>>>
>>>> Suppose I have to classes:
>>>> 1. A inherits UserControl
>>>> 2. B inherits A
>>>>
>>>> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
>>>>
>>>> Then suppose I want to instantiate control B. I have three options:
>>>> 1. Propgrammatically instatiate B through new B();
>>>> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
>>>> 3. Declare control B in ASPX/ASCX of a container and refer B in
>>>> code-behind file of a container.
>>>>
>>>> The quiestion is the following: Which of instantiation options are
>>>> correct to use?
>>>>
>>>> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
>>>> being parsed, so those children of A (from ASCX) are not being created.
>>>>
>>>> TIA
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web usercontrol + delegates or specialised usercontrol base class info@record-play.com ASP .Net 0 06-23-2006 09:41 AM
Web UserControl inheritance in VS 2005 Yuan ASP .Net 1 01-26-2006 02:15 AM
Web Usercontrol in a Web Usercontrol not displaying... Kan Grewal ASP .Net Web Controls 2 07-07-2004 08:12 AM
Web UserControl and Visual Inheritance Ben Fidge ASP .Net 1 06-08-2004 09:33 AM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57