I have been having trouble. For the past two days I have been trying to create a webpart that has two text boxes and a bunch of a Links as buttons (brand issue no nasty submit buttons).
I had a bit of Jscript that called the navigate of my main image link button so it did a post back. This worked till I did a little more testing with more parts and the add new web part sidebar opened. Every time I hit enter in this scenario it started adding web parts. At first I thought some clown is messing with my test portal, but soon realised that the submit button of the form was being executed. So I added a cancelBubble. No joy. I tried various incarnations of the __doPostBack call to see if that was the problem. (its been a while since I did real hardcore jscript ie4/5 change over period last time, so cancelBubble was all I knew about event problems).
I found this article by Dino.
http://cs2themax.com/ShowContent.aspx?ID=de009ab9-e7e4-42cb-b12f-d7364911b799
It is some code for a PostTextBox that fires an enter pressed, well thought piece of work, goes a little beyond what I had in mind, but essentially the same code client side with the bonus server side event thrown. Well as you can guess this works fine on a single form page, but anything more complicated and forget it, exactly the same problems again.
I gave up. So I thought Ajax. That will do, done that before 8 years ago, so I knocks up more jscript with http request to my webservice. Works great and fast, but I was concerned about the client installations having MSXML on them. A bit of a scout round and other standard desktops give me security messages, as obviously I’m accessing a web service that is not on the portal web. Can’t have that. I know I’ll go real old school and hidden Iframe my posts instead. And Again in previous projects this approach works great as its contained within the same site, this time I get an access denied in trying to access the parent windows html and the parent just cant access the child’s html.
ARRRRRRGGHHHH.
What next, I know I ‘ll know up a http fetcher page in portal so I can call it local and it returns the results as a local proxy. No too evil.
So back to google. I need to get the postback working.
This guy came to the rescue.
http://blogs.wwwcoder.com/prodigal/archive/2005/05/04/3958.aspx
Two additional lines of code to my original and it all works
window.event.returnValue = false;
window.event.cancel = true;
Had no idea about returnValue, some dim recollection of event.cancel, but I never thought to put that in. now I have.
My web part works I can hit enter and I get my search results, not as slick as AJAX or hidden IFRAME (which by the way is how the old Plumtree gadget I wrote worked). but problem solved.
Lets make it better.
Merge the two. I now have a PostTextBox control that has enter hit events and doesn’t give me additional postbutton grief.