473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I inherit controls?

Sorry for posting another question, but I can't seem to get the hang of
ASP.Net. In windows apps if I want to extend a control I would just
create a class that inherits from that control and do
add/overload/override the necessary properties and methods. This
apparently doesn't work in Asp.Net, or at least I can't get it to.

Take the simple class below:

public class MyTextBox : System.Web.UI.W ebControls.Text Box
{
public MyTextBox()
{
}

public String HelloWorldText
{
get
{
return "Hello World";
}
}

public void ChangeText()
{
this.Text = this.HelloWorld Text;
}
}

I then added the below to the host page to load the control (since I
couldn't find out how to do it at design time):

protected void Page_Load(objec t sender, EventArgs e)
{
Page.Controls.A dd(new MyTextBox());
}

When run this fails with the error "Control 'ctl02' of type 'MyTextBox'
must be placed inside a form tag with runat=server."

I have no idea what this means (this is still my first ASP.Net app),
could any of you experts offer some guidance as to how I should extend
a control?

Thanks in advance!

Dec 29 '06 #1
3 1944
<ju************ *@yahoo.comwrot e in message
news:11******** *************@a 3g2000cwd.googl egroups.com...
When run this fails with the error "Control 'ctl02' of type 'MyTextBox'
must be placed inside a form tag with runat=server."

I have no idea what this means (this is still my first ASP.Net app),
could any of you experts offer some guidance as to how I should extend
a control?
I appreciate that you're a newbie, but a quick Google search on the error
message you're getting would have given you the answer straightaway:
http://www.google.co.uk/search?sourc...at%3dserver%22

In ASP.NET, webcontrols need to be created in a server-side <formobject.
It's a good idea to use an <asp:Panelcontr ol for custom controls, as it
gives you an extra bit of control over where they get created, e.g.

<form id="frmDefault " runat="server">
<asp:Panel ID="pnlControls " runat="server">

</asp:Panel>
</form>

Now, you should be able to do:

pnlControls.Con trols.Add(new MyTextBox());

You should really consider getting a beginner's guide to ASP.NET and working
your way through it.
Dec 29 '06 #2
Thanks for the help again, I really appreciate it. I'll try out your
suggestions and the ones on the link you provided.
I appreciate that you're a newbie, but a quick Google search on the error
message you're getting would have given you the answer straightaway:
To redeem myself a little, I did search for things like "inherit
control" and "extend control", but I failed to run the now obvious
search for the error message. Sorry about that, I'll try to learn from
this mistake and spend more time searching before posting in the
future.
You should really consider getting a beginner's guide to ASP.NET and working
your way through it.
Any recommendations ? I don't really need help with the language (I'm
well grounded in C#)
I just don't understand the Asp.net programming model and it's
differences with windows apps (all my experience is with windows apps).
Besides books, are there any good websites that might have this info
available?

Thanks again for your time!
Mark Rae wrote:
<ju************ *@yahoo.comwrot e in message
news:11******** *************@a 3g2000cwd.googl egroups.com...
When run this fails with the error "Control 'ctl02' of type 'MyTextBox'
must be placed inside a form tag with runat=server."

I have no idea what this means (this is still my first ASP.Net app),
could any of you experts offer some guidance as to how I should extend
a control?

I appreciate that you're a newbie, but a quick Google search on the error
message you're getting would have given you the answer straightaway:
http://www.google.co.uk/search?sourc...at%3dserver%22

In ASP.NET, webcontrols need to be created in a server-side <formobject.
It's a good idea to use an <asp:Panelcontr ol for custom controls, as it
gives you an extra bit of control over where they get created, e.g.

<form id="frmDefault " runat="server">
<asp:Panel ID="pnlControls " runat="server">

</asp:Panel>
</form>

Now, you should be able to do:

pnlControls.Con trols.Add(new MyTextBox());

You should really consider getting a beginner's guide to ASP.NET and working
your way through it.
Dec 29 '06 #3
<ju************ *@yahoo.comwrot e in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
To redeem myself a little, I did search for things like "inherit
control" and "extend control", but I failed to run the now obvious
search for the error message. Sorry about that, I'll try to learn from
this mistake and spend more time searching before posting in the
future.
No problem. Generally speaking, when I come across a problem, I look for
help in the following places (in order):

1) Visual Studio.NET's own help system - if it's found an error, especially
while debugging, chances are it knows *exactly* what has caused it...

2) http://msdn.microsoft.com/library

3) http://www.google.com

4) These newsgroups
>You should really consider getting a beginner's guide to ASP.NET and
working
your way through it.

Any recommendations ? I don't really need help with the language (I'm
well grounded in C#)
I just don't understand the Asp.net programming model and it's
differences with windows apps (all my experience is with windows apps).
http://www.amazon.com/ASP-NET-All-Re...e=UTF8&s=books
http://www.amazon.com/ASP-NET-Everyd...e=UTF8&s=books

The "Dummies" series of books are uniformly excellent, though I really hate
the titles! Not knowing about one particular subject does not make a person
dumb per se - I don't know how to fly an aeroplane, but I don't consider
that that makes me "dumb" in any way... Why they couldn't have used the word
"Beginners" instead of "Dummies" I'll never know... :-)
Besides books, are there any good websites that might have this info
available?
Again, Google is your friend...:-)
http://www.google.co.uk/search?sourc...enet+tutorials
Dec 29 '06 #4

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

Similar topics

5
1578
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a 2 page Tab Control for users to add a Job in my application. The first page is for them to choose which type of Job they would like. The type of Job determines what information is asked for on the second page, and so will determine the layout of the second page. So this second page needs to be determined at runtime really when they select the Job Type on page 1. I thought I could maybe define...
1
5971
by: Spurry Moses | last post by:
Hi, I'm converting a project from C++Builder to C# and I just need to copy my class design across. It's looking good so far. To stick with the design I want to inherit from a ComboBox control (ie MyComboBox). I don't need to do anything flash with it, just add a few properties and methods. I'd almost solved this while writing this post but I'll just confirm what I'm doing is OK. It was a bit awkward in Visual Studio because all of...
0
1237
by: Janaka | last post by:
I'm using Web Matrix and a custom built DLL which I've placed in my /bin directory for my website on a Windows 2003 server. I'm using the same setup which worked previously on Windows 2000. Any of the classes in the dll which need to be instantiated work correctly. for example the following is fine: public class Tester { public int Add(int x, int y) {return x + y;}
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
4592
by: Jill Graham | last post by:
Hi folks, The pages of my website are built dynamically and are based on templates. A template can look like this : <table> <tr><td>This is the page header</td></tr> <tr><td>This is the page content</td></tr> <tr><td>This is the page footer</td></tr>
3
1179
by: Station Media | last post by:
Hi everybody, I need to create a custom button for all our internal applications, and i would like to know what is the best for this type of control(button), is it to inherit standard button or create a full new one with usercontrol (using GDI+) ? Which one will be the fatest or is it the same speed to display button on screen (form with more than 100 buttons) ? thank you
3
4168
by: jefftyzzer | last post by:
Friends: I have a stored procedure declared as: CREATE PROCEDURE X.Y LANGUAGE SQL DYNAMIC RESULT SETS 1 READS SQL DATA SPECIFIC Y INHERIT SPECIAL REGISTERS
3
1664
by: Guillaume Hanique | last post by:
Hi, I feel very stupid. I simply want to derive a control from system.web.ui.webcontrols.button and use that on my webform, but I just can't get it done. Can anyone tell me how to do that? I can create my own usercontrol (Menu: Website Add new item... Web User Control). This creates an aspx and an aspx.vb file in the root folder, which inherits nicely from system.web.ui.usercontrol. But I want to inherit...
5
2467
by: DAVE P | last post by:
i want to extend the progress bar control via inheritance my question is...in the ide how can i expose the inherited control for instance can i ad my inherited control in the tool box or is there a property that has control inherits from thanks dave
0
10364
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
10172
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...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7517
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
6750
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();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
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.