In the below code , what is the 'e' in 'e.X.ToString()' and how do you know that you have to use the letter 'e', what does it represent , I can get around this bit


please help

public partial class ImageTest : System.Web.UI.Page
{
protected void ImgButton_ServerClick(Object sender,
ImageClickEventArgs e)
{
Result.InnerText = "You clicked at (" + e.X.ToString() +
", " + e.Y.ToString() + "). ";
if ((e.Y < 100) && (e.Y > 20) && (e.X > 20) && (e.X < 275))
{
Result.InnerText += "You clicked on the button surface.";
}
else
{
Result.InnerText += "You clicked the button border.";
}
}
}

Recommended Answers

All 3 Replies

e is a class of type ImageClickEventArgs.
It is an argument of the ImgButton_ServerClick method.
The other argument is sender which is of type Object.
It is some sort of convention to name these arguments that way.

I don't know why people do name their arguments e; I've always named mine close to the event type itself. Like EventArgs is eaThisPartDependsOnMethodNameLOL. Well at least it was answered correctly before I got here. LOL

I use e just because I think VS uses it by default, instead of confusing future viewers of my code, I keep the e. Chances are high that they will know what it is when reading an event triggered method.

Could just be me being naive though.

commented: e for eventargs, everyone recognizes it. Just use it :) +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.