T
tshad
I am just getting started with events and had a couple of questions on why
they do what they do.
If you have a textbox and you want to handle an event you can just do:
this.TextBox2.TextChanged += new
EventHandler(TextBox2_TextChanged);
and then have the function.
void TextBox2_TextChanged(object sender, EventArgs e)
{
Response.Write(this.TextBox2.Text);
}
Here the event is created and tied to the control and function.
But if you do it in a user control, the function doesn't seem to be tied to
anything.
For example, in my .ascx page I could have this:
public event EventHandler BubbleTextChanged;
//protected void OnBubbleTextChanged(EventArgs e)
//{
// //if (BubbleTextChanged != null)
// //BubbleTextChanged(this, e);
//}
Where I normally wouldn't comment out the function, so it isn't tied to
anything (or doesn't seem to be). And the function seems to always need the
word "on" in front of it.
If I had 3 events (and no functions) they would show up in intellisense with
"on" in front of them:
public event EventHandler A1;
public event EventHandler B1;
public event EventHandler C1;
public event EventHandler D1;
public event EventHandler E1;
If I only had the above and nothing more, in my aspx page my intellisense
would show:
onA1
onB1
onC1
onD1
onE1
Yet in my first example, the event was TextBox2.TextChanged no
TextBox2.onTextChanged or the event that was tied to that:
TextBox2_TextChanged wasn't onTextBox2_TextChanged.
Why is it different?
Thanks,
Tom
they do what they do.
If you have a textbox and you want to handle an event you can just do:
this.TextBox2.TextChanged += new
EventHandler(TextBox2_TextChanged);
and then have the function.
void TextBox2_TextChanged(object sender, EventArgs e)
{
Response.Write(this.TextBox2.Text);
}
Here the event is created and tied to the control and function.
But if you do it in a user control, the function doesn't seem to be tied to
anything.
For example, in my .ascx page I could have this:
public event EventHandler BubbleTextChanged;
//protected void OnBubbleTextChanged(EventArgs e)
//{
// //if (BubbleTextChanged != null)
// //BubbleTextChanged(this, e);
//}
Where I normally wouldn't comment out the function, so it isn't tied to
anything (or doesn't seem to be). And the function seems to always need the
word "on" in front of it.
If I had 3 events (and no functions) they would show up in intellisense with
"on" in front of them:
public event EventHandler A1;
public event EventHandler B1;
public event EventHandler C1;
public event EventHandler D1;
public event EventHandler E1;
If I only had the above and nothing more, in my aspx page my intellisense
would show:
onA1
onB1
onC1
onD1
onE1
Yet in my first example, the event was TextBox2.TextChanged no
TextBox2.onTextChanged or the event that was tied to that:
TextBox2_TextChanged wasn't onTextBox2_TextChanged.
Why is it different?
Thanks,
Tom