Link to home
Start Free TrialLog in
Avatar of Niall Gallagher
Niall GallagherFlag for Ireland

asked on

Button_Click event always firing on Postback

I created a web page with a text box and a image button (used to open a calendar)
In The text box you have the option of doing a search by writing a name or ID in it or using the image button to open a calendar and when you click a date it is populated in the textbox for you to do a search by date.
When I write in a name and hit enter to do a search it always runs the button_click event so I get the calendar on top of my results.
Can somebody give me an idea what I might be doing wrong

Thanks in advance
Avatar of strickdd
strickdd
Flag of United States of America image

UseSubmitBehaviour="false" on the button
Avatar of Niall Gallagher

ASKER

Thank you for your help but I tried it on the imagebutton and it made no difference. The calendar still opened over the results
Avatar of Nasir Razzaq
What do you want to happen when you press enter? Do you have any other button on page?
When I press enter it should only post back the text put in the textbox to do the search. I only want the calendar to come up if I press the image button
Something I think I should mention incase it makes any difference although I am not doing anything with Ajax I have a ScriptManager on my Masterpage for using log4net
You need to have a button on the page which does the posting back to server. Or you would need to handle the keypress of the textbox in Javascript and post the page back if Enter is encountered.
I have always built my web pages so users only need to press enter to do a search but this is the first time I have had this problem. The keypress idea might work I must look up for examples on it and hopefully it will not cause the button_click event.
If you know of any good links with examples please let me know.
Thanks for your help
Doing some testing I used the Keypress event and said if Enter then alert('Hello') and it brought up the alert box but the calendar was behind it.......AAAAAAHHHHH
Check out Page.Form.SetDefaultButton & Panel.SetDefaultButton
ASKER CERTIFIED SOLUTION
Avatar of Niall Gallagher
Niall Gallagher
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I knew it had to be something simple and this was just a setting I missed