473,396 Members | 1,998 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,396 software developers and data experts.

Event handling in base classes in ASP.NET 2.0

I have recently upgraded a web project from ASP.NET 1.1 to ASP.NET 2.0,
and now the event handlers no longer work, due to the event handlers
being defined in base classes.

To start a bit of background, below is a simplified example, but the
same design pattern is used for many other pages:

In the ASPX file a button is defined:

<asp:Button Runat="server" Text="Login" id="btnLogin"></asp:Button>

The code behind file is implemented such:

Partial Class Login
Inherits BaseLogin

End Class

And the BaseLogin class:

Public Class BaseLogin
Inherits Page

Protected WithEvents btnLogin as New Button
' -CUT- other controls on the form

Protected Sub LoginUser(ByVal sender As Object, ByVal e As
EventArgs) Handles btnLogin.Click
' Lots of code that relies on other controls on the form

End Class
In ASP.NET 1.1, the ASP.NET compiler recognised that the base class
already defined a member called btnLogin, so it did not create one in
the ASP.NET page.

In ASP.NET 2.0, the ASP.NET compiler seems to create a member
regardless, which overrides the member defined in the base class. This
also results in an error saying that the variable should be declared
'Shadows'. The effect of this is the the Login.btnLogin and
BaseLogin.btnLogin are not pointing to the same object, which means
that the event handler (LoginUser) is not called.

What is the best way to fix it up so that the event handler in the base
class is called, considering that:
- The example above is simplified to illustrate the problem
- BaseLogin also has member variables for many of the other controls on
the form that it uses
- There are perhaps 8 different base classes with 50 implementing pages
- Each class has 1-5 event handlers

Regards,
Robert Wagner

Nov 20 '06 #1
0 994

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

Similar topics

3
by: boxboy | last post by:
I am hoping someone from Microsoft could shed some insight into this question. Why did microsoft decide to use a verb based naming convtion for events rather such as Close and Click for rather...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
4
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
2
by: Andrew Ducker | last post by:
My UserControl base class has an event handling method in it. I want to use this for several controls on a subclass of this base class. Normally, I can just click on the drop-down and the methods...
15
by: Pohihihi | last post by:
This might sound little stupid to many but I was thinking that when we can use object why we really need event args to pass in any functions e.g. bool MyFunction(object sender, System.EventArgs...
3
by: johncee | last post by:
Greetings, I created a base class that has a datagrid. I've made it generic as possible so that any derived classes pass some info to the base constructor (including a SQL select stmt) &...
7
by: c#2006user | last post by:
Hi all i have a c# problem, i have a base class Page and a good few classes inheriting from it. the events and delegates are declared in the base class page but different classes have different...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
3
by: =?Utf-8?B?RWR3aW4=?= | last post by:
Hello Everyone. Below is the code that is in question. --- BEGIN CODE WITHIN INHERITED FORM --- protected virtual void OnFormClosing(object sender, FormClosingEventArgs e) { switch...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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
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...
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,...

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.