Event handling in base classes in ASP.NET 2.0

D

droyad

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top