Solved

Adding onclientclick to an Image button

Posted on 2014-10-06
3
224 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

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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