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

New & confused-Possible to inherit aspx forms?

P: n/a
Greetings
I am beginning a web app. I am using C# aspx forms for my web pages.
Is it possible to create/use one aspx file as a base from which to
derive other aspx files? I can not get this to work.
What I tried was this:
Create a new web project.
- rename WebForm1.aspx to MyBase.aspx
- Add (grad from tool box) a label to the html form
- Then create another aspx file (using "Add Web Form"). This produces
WebForm2.aspx.
- Then, I tried several ways of getting WebForm2.aspx to inherit or
appear like MyBase
1. In the WebForm2.aspx.cs file, I changed the class declaration
to:
Public Class WebForm2 : MyBase.aspx{
........
}
No good.
2. In the html view I changed the first line parameters to:
Codebehind="MyBase.aspx.cs"
&
Inherits="MyBaseNameSpace.MyBase.aspx"
No good.
3. A combination of both of the above also does not work

No Matter what I do, I can get the WebForm2 page to load, but it does
not display the label that I have on the base page.

I find lots of references too and documentation about inheriting
windows forms, but nothing on web pages(forms)
Can this be done somehow?

Thanks
Jeff
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Take a look at user controls. I think that may be the answer to what you
are really trying to do.

--

Derek Davis
dd******@gmail.com

"Jeff" <je*******@hotmail.com> wrote in message
news:0o********************************@4ax.com...
Greetings
I am beginning a web app. I am using C# aspx forms for my web pages.
Is it possible to create/use one aspx file as a base from which to
derive other aspx files? I can not get this to work.
What I tried was this:
Create a new web project.
- rename WebForm1.aspx to MyBase.aspx
- Add (grad from tool box) a label to the html form
- Then create another aspx file (using "Add Web Form"). This produces
WebForm2.aspx.
- Then, I tried several ways of getting WebForm2.aspx to inherit or
appear like MyBase
1. In the WebForm2.aspx.cs file, I changed the class declaration
to:
Public Class WebForm2 : MyBase.aspx{
........
}
No good.
2. In the html view I changed the first line parameters to:
Codebehind="MyBase.aspx.cs"
&
Inherits="MyBaseNameSpace.MyBase.aspx"
No good.
3. A combination of both of the above also does not work

No Matter what I do, I can get the WebForm2 page to load, but it does
not display the label that I have on the base page.

I find lots of references too and documentation about inheriting
windows forms, but nothing on web pages(forms)
Can this be done somehow?

Thanks
Jeff

Nov 17 '05 #2

P: n/a
Try to understand what you are doing.

1) You create an ASPX page (an HTML file that will be processed by the
ASP.NET framework) and you put a label on it by dragging it from the
toolbox.
2) In your codebehind you can see a declaration of this component.

Try to delete the CodeBehing and the codebehind and inherits tags in
the Page directive on your aspx.

Compile and check the result.

The label is still there.

This can show you that the component declaration and placement is
happening somewhere else, in fact, it is happening inside the class
that is compiled from your ASPX page. When you ask for an ASPX page,
the ASP.NET framework compiles a dynamic class from your aspx page,
that inherits from the code-behind file (that's why protected
declarations and not private). Theoritically you could put code and
components in the same aspx file and everything should work.

Now, you take the codebehind, which has NO information about the
components registration and placement and you derive a page from it.
As you can understand, this will not work.

In order to have this kind of "visual inheritance" you must put the
registration/placement logic in the class that you inherit, in our case
the code behind class.

I hope that this will clarify the situation. You should also check this
:
ms-help://MS.MSDNQTR.2005APR.1033/vbcon/html/vbconWebFormsCodeModel.htm

Nov 17 '05 #3

P: n/a
Tasos

I looked at the help reference that you suggested. They basically
describe placing code (scripts) in the html file, if I want to use
only one file instead of two. I understand that, I have seen classic
ASP.

Now, if I understand this, you are proposing a different approach:
In order to have this kind of "visual inheritance" you must put the
registration/placement logic in the class that you inherit, in our case
the code behind class. Can I write the html/ASP (registration/placement logic ) from within a
code behind file and get it to display?

If I could do this, then I could set up a base page (aspx.cs) for my
repetitive labels, etc, and then refer subsequent aspx.cs pages to
inherit from this, rather than from System.Web.UI.Page.
Is that correct?

Thanks
Jeff

On 24 Sep 2005 19:51:01 -0700, "Tasos Vogiatzoglou"
<tv*****@gmail.com> wrote:
Try to understand what you are doing.

1) You create an ASPX page (an HTML file that will be processed by the
ASP.NET framework) and you put a label on it by dragging it from the
toolbox.
2) In your codebehind you can see a declaration of this component.

Try to delete the CodeBehing and the codebehind and inherits tags in
the Page directive on your aspx.

Compile and check the result.

The label is still there.

This can show you that the component declaration and placement is
happening somewhere else, in fact, it is happening inside the class
that is compiled from your ASPX page. When you ask for an ASPX page,
the ASP.NET framework compiles a dynamic class from your aspx page,
that inherits from the code-behind file (that's why protected
declarations and not private). Theoritically you could put code and
components in the same aspx file and everything should work.

Now, you take the codebehind, which has NO information about the
components registration and placement and you derive a page from it.
As you can understand, this will not work.

In order to have this kind of "visual inheritance" you must put the
registration/placement logic in the class that you inherit, in our case
the code behind class.

I hope that this will clarify the situation. You should also check this
:
ms-help://MS.MSDNQTR.2005APR.1033/vbcon/html/vbconWebFormsCodeModel.htm


Nov 17 '05 #4

P: n/a
The reference I sent you was the WebForms code model and it describes
how webforms work.

Yes ... You could add initialization logic to a Page derived class and
inherit this behaviour to your own pages.

Keep in mind that this way you wont have the advantages of the
designer. Maybe you should consider some other alternative if you have
complicated UI inheritance.

Nov 17 '05 #5

P: n/a
Tasos
Perhaps I will scrap the page inheritance idea for now.
It appears more trouble that I thought it was worth.

Thanks alot
Jeff

On 25 Sep 2005 06:44:01 -0700, "Tasos Vogiatzoglou"
<tv*****@gmail.com> wrote:
The reference I sent you was the WebForms code model and it describes
how webforms work.

Yes ... You could add initialization logic to a Page derived class and
inherit this behaviour to your own pages.

Keep in mind that this way you wont have the advantages of the
designer. Maybe you should consider some other alternative if you have
complicated UI inheritance.


Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.