Solved

Adding onclientclick to an Image button

Posted on 2014-10-06
3
223 Views
Last Modified: 2014-10-06
I'm trying to add onclientclick javascript code to an Image Button from VB code behind.   if I add it in directly in the aspx, it works OK.   Like this:  

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../Images/DateSelector.gif"
                onclientclick="imageClick();

but if I add from server in code behind like below, it does not work; the javascript imageClick() is never executed when the button is clicked;  what am I doing wrong?

ImageButton1.Attributes.Add("onclientclick", "imageClick();")
0
Comment
Question by:HLRosenberger
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Robert Saylor earned 500 total points
ID: 40364369
I had something like this with PHP and adding ;return false; at the end fixed it for me on a jquery issue. Now, I have no clue about VB but worth a try.

ImageButton1.Attributes.Add("onclientclick", "imageClick();return false;") 

Open in new window

0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40364409
Ah, yes.  Your answer rung a bell with me.  Ya have to use onClick with return false.  This is equivalent to onclickclient.   The return false tells the client to NOT pass the click event along to the server;  return true will pass it along to the server.

ImageButton1.Attributes.Add("onclick", "imageClick();return false;")
0
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 40364425
sweet glad I was able to help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question