473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

can webform inherit controls from another web form

I have trying to have a webform inherit controls from another form and can't
get it to work

Say I have a form that saves the person's demographic info.

****one.aspx****

//I have an object to save the person's name in code behind

protected void SavePersonInfo(Person p)

{

p.First = txtFirstName.Text;

p.Last = txtLastName.Text;

p.Save();

}

******************

Then I have another customer that wants the same form, but would like the
person's gender and age in additioon to the first and last names.

Ideally, I should be able to have a form that inherits the form above and do

****derived.aspx**************

protected new void SavePersonInfo(Person p)

{

p.Age = txtAge.Text;

p.Gender = cmbGender.SelectedValue;

base.SavePersonInfo();

}

********************
I just don't want to have to repeat the code behind for first and last names
for the second customer's form. So ideally the derived form inherits
txtFirstName and txtLastName.

But the problem is VS.NET won't let you. When I draw txtFirstName, and
txtLastName, VS.NET keeps declaring them as class level controls in the
derived class. I comment them out and they keep coming back. After I comment
them out, I can compile and run and the code expects the way I want it to,
but the bam, these two lines keep come back again.

protected TextBox txtFirstName;

protected TextBox txtLastName;
Nov 18 '05 #1
4 2455
If you take out the codebehind attribute then when you're editing the
page VS.net won't try to help by adding in the additional fields.

"David" <sp************@spammers.go.home.com> wrote in message
news:1V***************@twister.socal.rr.com...
I have trying to have a webform inherit controls from another form and can't get it to work

Say I have a form that saves the person's demographic info.

****one.aspx****

//I have an object to save the person's name in code behind

protected void SavePersonInfo(Person p)

{

p.First = txtFirstName.Text;

p.Last = txtLastName.Text;

p.Save();

}

******************

Then I have another customer that wants the same form, but would like the person's gender and age in additioon to the first and last names.

Ideally, I should be able to have a form that inherits the form above and do
****derived.aspx**************

protected new void SavePersonInfo(Person p)

{

p.Age = txtAge.Text;

p.Gender = cmbGender.SelectedValue;

base.SavePersonInfo();

}

********************
I just don't want to have to repeat the code behind for first and last names for the second customer's form. So ideally the derived form inherits
txtFirstName and txtLastName.

But the problem is VS.NET won't let you. When I draw txtFirstName, and
txtLastName, VS.NET keeps declaring them as class level controls in the derived class. I comment them out and they keep coming back. After I comment them out, I can compile and run and the code expects the way I want it to, but the bam, these two lines keep come back again.

protected TextBox txtFirstName;

protected TextBox txtLastName;

Nov 18 '05 #2
What do you mean? The aspx page needs know where its codebehind is, so how
can you take out that attribute. I am not understanding what you mean by
"take out the codebehind attribute." Thanks in advance..

"matt" <gr************@hitscricket.com> wrote in message
news:7Z*********************@stones.force9.net...
If you take out the codebehind attribute then when you're editing the
page VS.net won't try to help by adding in the additional fields.

Nov 18 '05 #3
The codebehind attribute is only needed by visual studio not by ASP.Net.
For the page to be served correctly you just need to inherit from the
correct class, if you do not set the codebehind attribute then visual
studio will not make changes to the class you inherit from, which should
solve your problem.

for example...

<%# Page language="c#" AutoEventWireup="false"
Inherits="MyNamespace.MyClass" %>

Matt

"David" <sp************@spammers.go.home.com> wrote in message
news:ft**************@twister.socal.rr.com...
What do you mean? The aspx page needs know where its codebehind is, so how can you take out that attribute. I am not understanding what you mean by "take out the codebehind attribute." Thanks in advance..

"matt" <gr************@hitscricket.com> wrote in message
news:7Z*********************@stones.force9.net...
If you take out the codebehind attribute then when you're editing the page VS.net won't try to help by adding in the additional fields.


Nov 18 '05 #4
Thanks. I got it to work, but...

When I want to hide (new) the base form's behavior (say the button event
handler), and the base forms' fields as well as the event handler, I run
into the following problem.

You have to take out base.OnInit(e) in the derived form's OnInit(EventArgs
e). If you don't, then the base form's InitializeComponent executes, and
will throw an Null Exception error since it can't find any of the declared
controls (the derived form hides them with "new"). I just don't know the
ramifications of taking out base.OnInit(e) is and I am not sure if that is
something I should mess with.

It is getting a bit too complicated and is defeating code maintenanbility,
which was my original intent.

"matt" <gr************@hitscricket.com> wrote in message
news:pM*********************@wards.force9.net...
The codebehind attribute is only needed by visual studio not by ASP.Net.
For the page to be served correctly you just need to inherit from the
correct class, if you do not set the codebehind attribute then visual
studio will not make changes to the class you inherit from, which should
solve your problem.

for example...

<%# Page language="c#" AutoEventWireup="false"
Inherits="MyNamespace.MyClass" %>

Matt

"David" <sp************@spammers.go.home.com> wrote in message
news:ft**************@twister.socal.rr.com...
What do you mean? The aspx page needs know where its codebehind is,

so how
can you take out that attribute. I am not understanding what you mean

by
"take out the codebehind attribute." Thanks in advance..

"matt" <gr************@hitscricket.com> wrote in message
news:7Z*********************@stones.force9.net...
If you take out the codebehind attribute then when you're editing the page VS.net won't try to help by adding in the additional fields.



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Phillip N Rounds | last post by:
I have a webform, from which I have to submit info to another site. Their instructions are to have a html form, with the following as the submit: <form method="post"...
6
by: Zingam | last post by:
Is it possible to insert a WinForm in a WebForm? I'd like for example to insert a managed directx viewer in a webform, that would display 3d graphics on the form? Is this possible? Regards,...
1
by: Rahim | last post by:
i want to change all the label control style Properties, server control properties at runtime how should i call all the label at runtime, which is present at webform, any collections???? i...
4
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object...
3
by: Nuno | last post by:
How can I instantiate a webform2 object from webfrom1 codebehind? The class does not popup in intellisense and gives me and error if i try to create it. Nuno
3
by: Gordon | last post by:
Hi; Can you add a column of button controls to a winform datagrid ? I have a form with three independant grids. I would like to add buttons i.e. update, add buttons at the end of each row....
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have start web form and when the user clicks a button (server.transfer) they are directed to the second webform. I was wondering if there is a way to create an instance of the first webform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.