Solved

Adding onclientclick to an Image button

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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