• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1329
  • Last Modified:

ASP.net 2.0 OnClientClick imageButton problem.

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?
1 Solution
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?
The javascript in the onClientClick is incorrect

it should be like this:
onclick="document.location.href = 'http://www.webspider.com/69218 Sample by Meyda Tiffany_13494513.html';"
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.
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.
jumpstart0321Author Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now