3

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

2 Answers 2

4

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'");

    }
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way to do it without JavaScript?
@lsxliron yes you can use DHTML to add event to the html elments and react to this events.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.