Reputation: 540
I'm building a website using ASP and C# and I wanted to know if it's possible to add a custom events to an asp control.
I want to add an OnClick, OnMouseDown, OnMouseUp (etc.) event to <asp:image>
.
Is it possible?
Thanks in advance
Upvotes: 3
Views: 595
Reputation: 3274
yes you can do it this way.
HTML
<asp:Image runat="server" ID="Image1" />
CODE BEHIND
protected void Page_Load(object sender, EventArgs e){
this.Image1.Attributes.Add("onmouseup", "alert('this is the OnMouseUp event')");
}
EDIT
It can be do it using DHTML but as you may know
DHTML is the art of combining HTML, JavaScript, DOM, and CSS.
protected void Page_Load(object sender, EventArgs e){
//change the Image Url when the click event fire
this.Image1.Attributes.Add("onclick", "this.src='image1.jpg'");
}
Upvotes: 4
Reputation: 1
Note that mouse events may be impractical to be handled on the server, It's better for them to be handled locally (quicker) on the client, so the network speed does not have an impact on how fast your event is processed.
Upvotes: 0