2
2obvious
I'm trying to wrap my mind around writing reusable event handlers.
Say I have a textbox control. In the OnTextChanged event handler of
this textbox control, I want to call a subroutine that does something
to another control (a label control, in this pseudo example):
<asp:textBox id="txt1" OnTextChanged="txtFunction1" ... />
sub txtFunction(sender as Object, e as EventArgs)
lblAnotherControl.Text = "blah"
end sub
But say I want to use this same subroutine on a different textbox
control to affect a different (label) control. My experience tells me
I want to pass the subroutine some arguments. But that doesn't seem to
be an option with ASP.NET. In ASP.NET, it seems my only recourse is to
write a new subroutine for each event handler, regardless of how
similar each subroutine may be. Since this is contrary to the concepts
of modularity and code reuse, I figure I must be interpreting things
wrong.
Can someone please explain to me how .NET takes on situations like the
one in my example, or how it provides a different approach that
circumvents such questions (if it does)?
Say I have a textbox control. In the OnTextChanged event handler of
this textbox control, I want to call a subroutine that does something
to another control (a label control, in this pseudo example):
<asp:textBox id="txt1" OnTextChanged="txtFunction1" ... />
sub txtFunction(sender as Object, e as EventArgs)
lblAnotherControl.Text = "blah"
end sub
But say I want to use this same subroutine on a different textbox
control to affect a different (label) control. My experience tells me
I want to pass the subroutine some arguments. But that doesn't seem to
be an option with ASP.NET. In ASP.NET, it seems my only recourse is to
write a new subroutine for each event handler, regardless of how
similar each subroutine may be. Since this is contrary to the concepts
of modularity and code reuse, I figure I must be interpreting things
wrong.
Can someone please explain to me how .NET takes on situations like the
one in my example, or how it provides a different approach that
circumvents such questions (if it does)?