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

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
0
Niall292
Asked:
Niall292
1 Solution
 
strickddCommented:
UseSubmitBehaviour="false" on the button
0
 
Niall292Author Commented:
Thank you for your help but I tried it on the imagebutton and it made no difference. The calendar still opened over the results
0
 
CodeCruiserCommented:
What do you want to happen when you press enter? Do you have any other button on page?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Niall292Author Commented:
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
0
 
Niall292Author Commented:
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
0
 
CodeCruiserCommented:
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.
0
 
Niall292Author Commented:
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
0
 
Niall292Author Commented:
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
0
 
Bill NolanCommented:
Check out Page.Form.SetDefaultButton & Panel.SetDefaultButton
0
 
Niall292Author Commented:
I tried the SetDefaultButton but to no avail.
I also have to apologise because I knew it had to be something simple as I never had this problem before.
I went into the properties of the textbox and set the Auto Postback = true and it worked
NO MORE CALENDAR
0
 
Niall292Author Commented:
I knew it had to be something simple and this was just a setting I missed
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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