R
rn5a
A user control file named Address.ascx has 4 TextBoxes. The logic of
this user control is encapsulated in a code-behind file named
Address.ascx.vb. The code-behind also defines an Event named
"TextChangedEvent" which handles the TextChanged event of the 4
TextBoxes.
Namespace Address
Public Class AddressCB : Inherits UserControl
Public txt1 As TextBox
Public txt2 As TextBox
Public txt3 As TextBox
Public txt4 As TextBox
..........
..........
Public Event TextChangedEvent(ByVal obj As Object, ByVal ea As
EventArgs)
Protected Sub txt1Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt1.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt2Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt2.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt3Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt3.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt4Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt4.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
End Class
End Namespace
When the user control is executed, ASP.NET generates the following
error:
Handles clause requires a WithEvents variable defined in the containing
type or one of its base types.
pointing to the
Protected Sub txt1Changed(........)
line. I resolved the problem by declaring the 4 TextBoxes shown above
using WithEvents
Public WithEvents txt1 As TextBox
Public WithEvents txt2 As TextBox
Public WithEvents txt3 As TextBox
Public WithEvents txt4 As TextBox
Though my problem has been resolved, I couldn't exactly understand what
the error message means especially the part "defined in the containing
type or one of its base types". Can someone please explain me what does
"defined in the containing type or one of its base types" mean? Which
is the "containing type" here? Also does "base types" refer to the user
control?
this user control is encapsulated in a code-behind file named
Address.ascx.vb. The code-behind also defines an Event named
"TextChangedEvent" which handles the TextChanged event of the 4
TextBoxes.
Namespace Address
Public Class AddressCB : Inherits UserControl
Public txt1 As TextBox
Public txt2 As TextBox
Public txt3 As TextBox
Public txt4 As TextBox
..........
..........
Public Event TextChangedEvent(ByVal obj As Object, ByVal ea As
EventArgs)
Protected Sub txt1Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt1.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt2Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt2.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt3Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt3.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt4Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt4.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
End Class
End Namespace
When the user control is executed, ASP.NET generates the following
error:
Handles clause requires a WithEvents variable defined in the containing
type or one of its base types.
pointing to the
Protected Sub txt1Changed(........)
line. I resolved the problem by declaring the 4 TextBoxes shown above
using WithEvents
Public WithEvents txt1 As TextBox
Public WithEvents txt2 As TextBox
Public WithEvents txt3 As TextBox
Public WithEvents txt4 As TextBox
Though my problem has been resolved, I couldn't exactly understand what
the error message means especially the part "defined in the containing
type or one of its base types". Can someone please explain me what does
"defined in the containing type or one of its base types" mean? Which
is the "containing type" here? Also does "base types" refer to the user
control?