473,652 Members | 3,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.btnLo gin 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 1006

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

Similar topics

3
5012
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 than prepending them with On as in OnClose and OnClick? The way it is now, I encounter a lot of naming conflicts/ambiguity when trying to follow Microsoft's reccommened approach in naming my own events.
8
6083
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 uses message queues to pass pointers to Events between threads. In my app there are simple events that can be defined using an enum (for example an event called NETWORK_TIMEOUT) and more complex events that contain data (for example an event called...
4
1746
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 protected method of the base class". Can someone please explain this with a sample code? Thanks a lot.
2
1443
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 that fit the correct signature appear - however ones from the base class don't! If I go in and change the generated code myself, it works - so things are set up correctly - it just doesn't appear in the dropdown. Anyone else encountered this?
15
4213
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 e){} my question is targetted more on the customized event arguments that we create while programming. Is it just to make it more readable or maybe to make things in collective and hierarchy?
3
1468
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) & through the base class, any db table can be displayed/maintained in the grid. I've made some of the base class' event-handling subs overridable and in some of the derived classes using the base, the subs are being overridden:
7
1477
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 methods for the same event, ie page_leave event would be different on the homepage than on an artistpage. how or where would i assignt the event methods?? any help appreciated.
2
2644
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
2163
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 (e.CloseReason) { case CloseReason.UserClosing: if (this.AskUserIfOkayToClose() == true) { this.ExecuteApplicationCloseProcedures(); }
0
8703
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
8467
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,...
0
8589
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
7302
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...
0
5619
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
4145
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
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.