Friday, November 22, 2013

onClick event not working in XPage Link Control - A work around

I have had issues with XPage Link Controls in the past, especially with the onClick events of the links. I was under an impression that I had a work around to solve it. Unfortunately I rediscovered that I still have issues with the same and my work around from the past failed.

It was because, I had a link with my known work around inside a table cell whose onClick event was coded.
My previous solution was for 8.5 version and with all of the new nice features in 8.5.3 I thought its time for me to go for a more stabler solution. And ended up with a better work around lol, may not be a perfect solution

In respect to my analysis, following is a possible list of reasons that your onClick event of XPage Link Controls would fail in 8.5.3

1. The onClick event of your Link Control might fail if you had associated a url to your link. Refer to the following image

2. When both URL and onClick events are provided on the XPage Link Controls, Page gets redirected to the linked url before its onClick event gets executed properly. Its a wild guess. Please check for its authenticity your self

3. The onClick event might fail on the wonderful IE browser if a parent container like a div or a table cell which contains the Link Control has code on its onClick event or other events like onMouseover etc

In order to over come all still be able to use both "link" and onclick event, remove the url mapping to the link control and use call a button controls onclick event on the client side onclick event of the link. And code all you want in the button both client and server side. This seems to remove alot of problems and has worked for me. I know that I am complicating stuffs with my words here, so take a look at the following image. Probably you would understand stuffs better.

And dont even think about screaming something like "HEY, THATS CHEATING. ITS NOT A FAIR SOLUTION". As I said earlier, this is a possible work around that has worked for me. I dont mean this to be a final solution :P


  1. I feel nuts. This did not work for me in an other instance on the same page where it is already working. Do u feel confused about what I am doing. I REALLY DO

    1. My Stupid Mistake. It is working. I labeled a button control as "test" instead of naming it in the XPage. So document.getElementById("#{id:test}") was always undefined, since the button's name was "button1"

      I AM OUT OF MY MIND :(