Solved

Adding onclientclick to an Image button

Posted on 2014-10-06
3
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 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