Solved 2.0 OnClientClick imageButton problem.

Posted on 2008-11-14
Last Modified: 2012-05-05
Here's the sample url:
I'm having a problem with getting the onClientClick to work. As you can see on the page, there is images and I have set all their URL's dynamically so that they link to the product descriptions. However, it doesn't seem to be working as you can see in the url. It just posts back to the same page. The page pops up with a script error at the exact location of the imageButton. Any ideas as to what's causing my problem?
Question by:jumpstart0321
    LVL 3

    Expert Comment

    Does your OnClientClick reference a JavaScript? OnClientClick is used for client side scripting OnClick is used for server side scripting. What is your script handled OnClientClick?
    LVL 9

    Expert Comment

    The javascript in the onClientClick is incorrect

    it should be like this:
    onclick="document.location.href = ' Sample by Meyda Tiffany_13494513.html';"
    LVL 3

    Expert Comment

    My other thought is that if all you want to do is link to another page you can use the PostBackUrl of the ImageButton to just enter a link. This can also be bound to if necessary.
    LVL 22

    Accepted Solution

    If all you need is to direct user to another page upon click, then use HyperLink instead of ImageButton. Set HyperLink's ImageUrl to the product's picture and set NavigateUrl to the destination url which can be constructed dynamically.
    The ImageButton control will cause postbacks, but HyperLink control will not.

    Author Comment

    Thanks for all the help guys. I didn't reference anyexternal javascript, however; I believe the control automatically makes its own javascript at runtime. I tried the PostBackURL and got the same result. I took prariedog's suggestion and just used a basic <a href... control. Much easier and I'm sure it will be more SEO compatible. Thanks again guys.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    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…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    755 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

    24 Experts available now in Live!

    Get 1:1 Help Now