473,756 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Te xt;

p.Last = txtLastName.Tex t;

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.asp x**************

protected new void SavePersonInfo( Person p)

{

p.Age = txtAge.Text;

p.Gender = cmbGender.Selec tedValue;

base.SavePerson Info();

}

*************** *****
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 2486
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.ho me.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.Te xt;

p.Last = txtLastName.Tex t;

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.asp x**************

protected new void SavePersonInfo( Person p)

{

p.Age = txtAge.Text;

p.Gender = cmbGender.Selec tedValue;

base.SavePerson Info();

}

*************** *****
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.co m> wrote in message
news:7Z******** *************@s tones.force9.ne t...
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="MyNam espace.MyClass" %>

Matt

"David" <sp************ @spammers.go.ho me.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.co m> wrote in message
news:7Z******** *************@s tones.force9.ne t...
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(EventArg s
e). If you don't, then the base form's InitializeCompo nent 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.co m> wrote in message
news:pM******** *************@w ards.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="MyNam espace.MyClass" %>

Matt

"David" <sp************ @spammers.go.ho me.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.co m> wrote in message
news:7Z******** *************@s tones.force9.ne t...
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
2140
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" action="http://www.theirsite.htm"> <input type=hidden name="field1" value="value1"> <input type=hidden name="field2> value="value2> <input type="submit" value="Click Me"> On my web form, I have numerous web controls ( all runat="server"), one of which is a button which...
6
2654
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, Z.
1
1468
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 can't remember each control name on the form. thanks help me
4
428
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 to save the person's name in code behind protected void SavePersonInfo(Person p)
3
1602
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
1891
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. Is this possible in a WINFORM in vb.net 2003 ?
5
2558
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 on the second webform? I have a base webform class that both webforms inherit webform1 : BaseWebclass webform2 :BaseWebclass so I do not think I can just inherit webform1 in webform2 thanks --
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.