Inheriting Webforms in C#

S

Simon

Hi,

Just to get started....

I've created a very simple web form, "Simple", using VS and I dropped a
HTML img control on the design view. I referenced a picture and it is
displayed in browser view. Very simple.

I have created a second form and in the code-behind page I have altered the
class definition to inherit from, "Simple".

When viewing the second form in the browser the 'inherited' image from the
first form is not shown.

Examples I have found of web form inheritance tend to all deal with the
"Simple" form being only a code page (a class) that renders its content in
code rather than having any design view.

Can a Webform only inherit content from a base class that is code only or
can content in the .aspx file also be inherited?

Thanks,

gramps
 
J

Josh

Big question. The HTML cant be inherited but there are workarounds such as
reading the HTML frmo a File and merging you content into it or it into your
content,.
 
K

Kevin Spencer

Hi Simon,

Let me see if I can explain a bit about WebForms, the CodeBehind model, and
Inheritance. Forgive me if I mention anything you already know; I just want
to cover all the bases. I will begin with Inheritance. Put simply, a class
that inherits another class obtains all of the characteristics of the
inherited class, Properties, Fields, Methods, etc. The new class can now
extend the inherited class by adding other characteristics to it. This, of
course, has no effect on the inherited class.

The CodeBehind model is a way of separating Interface (HTML and related
server-side tags) and Interface business logic. What you refer to as "design
view" is actually a Template. It inherits the CodeBehind class. If you take
a look at the HTML view of that file, you will see the Inherits statement in
the @Page tag. So, you can only inherit from the CodeBehind class.

IOW, if you want to inherit a Control from a Page class, it will have to be
declared in the CodeBehind class that you inherit from, and there will have
to be a tag in the inheriting template, or the Control will have to be
dynamically created in the CodeBehind.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top