473,468 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

User control question

I have created a VB.NET User Control which inherits from TextBox. I
have a general question regarding how functionality should be
overwritten:

I can either write a method which handles an event:

function MyControl_Enter(...) handles MyControl.Enter

or I can overwrite the relevant virtual method:

function overwrites onEnter(...)

Are these two ways of doing the same thing? When should I use the
first approach, and when the other?

Thanks for helping me understand this.
Nov 20 '05 #1
3 1387
When you create an event handler, you are 'Creating' a method which handles
an event, in otherwords you register this method address to be fired when a
certain event occurs. You are not overriding anything and you dont need to.

What changes are you trying to make ?
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"James Ramaley" <jr******@iname.com> wrote in message
news:f8**************************@posting.google.c om...
I have created a VB.NET User Control which inherits from TextBox. I
have a general question regarding how functionality should be
overwritten:

I can either write a method which handles an event:

function MyControl_Enter(...) handles MyControl.Enter

or I can overwrite the relevant virtual method:

function overwrites onEnter(...)

Are these two ways of doing the same thing? When should I use the
first approach, and when the other?

Thanks for helping me understand this.

Nov 20 '05 #2
James,
Is MyControl the name of the user control?

In addition to what OHM stated.

..NET does not allow a derived class from invoking a base event. Hence if you
wanted to raise the Paint event in your code you would not be able to. Yes
Yes, you should really use Invalidate & Update or Refresh on a form to cause
the Paint event to be raised, but bear with me. ;-)

So the pattern in .NET is to have an event MyEvent and an overridable method
OnMyEvent. The OnMyEvent when called will raise the MyEvent of the base.
Because its overridable derived classes can choose to do something before or
after calling the base class's OnMyEvent... Like replacing the event args
with a class derived from the normal event args adding addition
information...

Also, overriding a method is generally quicker than handling an event, at
least cleaner. So overriding the OnPaint method should perform better than
handling the Paint event, especially if there are other handlers of said
event...

The most important thing about overriding the OnPaint method (especially the
OnPaint) is to call the base class's OnPaint.

I think of it this way:
The OnPaint method is for notification internal to the object (the class,
classes I derive from, and classes that derive from me).
The Paint event is for notification external to the object (other objects).

In your example, I would override the OnEnter method, being sure to call
MyBase.OnEnter within my MyControl user control.

For example, when I design a form I normally override the OnLoad method,
instead of handling the MyBase.Load event (as the designer would have you
do).

Hope this helps
Jay
"James Ramaley" <jr******@iname.com> wrote in message
news:f8**************************@posting.google.c om...
I have created a VB.NET User Control which inherits from TextBox. I
have a general question regarding how functionality should be
overwritten:

I can either write a method which handles an event:

function MyControl_Enter(...) handles MyControl.Enter

or I can overwrite the relevant virtual method:

function overwrites onEnter(...)

Are these two ways of doing the same thing? When should I use the
first approach, and when the other?

Thanks for helping me understand this.

Nov 20 '05 #3
>
Hope this helps
Jay


Yes Jay, it does help a lot.

thanks
Nov 20 '05 #4

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

Similar topics

11
by: Lloyd Sheen | last post by:
Is there any one who has actually done this. I have now scanned more web articles about this with the realization that not one of them (including MSDN docs) outlines how to do this. This is...
6
by: Jim Heavey | last post by:
Hello, I have a user control which I place at the top of each page. I want to have code in this user control which sets the value of a couple of module variables and I was wondering if I create a...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
8
by: Prince Mathew | last post by:
Hi All, I have a requirement. I am throwing an exception from my user control I want to catch this in my container page. Is this possible? I don't want any event to be raised. PLEASE...
0
by: campwes | last post by:
Hey there. I have a user control on an aspx page that displays data based on a query (handled by another user control also on the page). I've noticed that the first time I navigate to the page...
0
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind...
0
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind...
1
by: weboweb | last post by:
Hello aspnet experts! I have a design question for the more experienced developers (more than me at least :-)). 1) I have a page in the application I'm building that displays a web user...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
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
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,...
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...
1
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...
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
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...
0
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...
0
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 ...

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.