Solved

Adding onclientclick to an Image button

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

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 6

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now