By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

Inheriting Webforms in C#

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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,.
Nov 19 '05 #2

P: n/a
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.

"Simon" <si**********@NO.SPAMiprimus.com.au> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.