By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

SearchForm triggers postback 2 times?

P: n/a
Hi,

I have a very simple searchform (an asp:textbox and a asp:button)

I have enabled autopostback for the textbox to be able to execute the search
method when the user hits the enter key.

Ofcourse the search should also be executed when clicking the search button.
Therefore I have added an empty eventhandler to recieve the click event. The
eventhandler is empty because I handle the postback in the page_load event:

if (Page.isPostBack)
{
search();
}
else
//do nothing - it's the first time the page is loaded

The problem is when I hit the search button the postback event is raised two
times, causing the search() method to be executed two times, which means
that the search result is being doubled.

If I hit the enter key after having entered something into the textbox, the
search method is executed just one time - as it should. How can I make sure
that the search method is only being executed one time no matter if it was
the enter key or the search button that was pressed/clicked by the user?

Thank you very much for your help.
Regards
Torben Jensen
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Are you handling the button click event as well?

"Torben Philippsen" <no@mail.dk> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Hi,

I have a very simple searchform (an asp:textbox and a asp:button)

I have enabled autopostback for the textbox to be able to execute the search method when the user hits the enter key.

Ofcourse the search should also be executed when clicking the search button. Therefore I have added an empty eventhandler to recieve the click event. The eventhandler is empty because I handle the postback in the page_load event:
if (Page.isPostBack)
{
search();
}
else
//do nothing - it's the first time the page is loaded

The problem is when I hit the search button the postback event is raised two times, causing the search() method to be executed two times, which means
that the search result is being doubled.

If I hit the enter key after having entered something into the textbox, the search method is executed just one time - as it should. How can I make sure that the search method is only being executed one time no matter if it was
the enter key or the search button that was pressed/clicked by the user?

Thank you very much for your help.
Regards
Torben Jensen

Nov 19 '05 #2

P: n/a

"Marina" <so*****@nospam.com> wrote in message
news:Oj*************@TK2MSFTNGP10.phx.gbl...
Are you handling the button click event as well?

No, the eventhandler for the button click event is empty.
The reason why it is empty is that I discovered that when the button is
clicked a server round trip was started. I handle the postback in the
page_load eventhandler:
if (Page.isPostBack)
{
search();
}

Since clicking the button causes a postback - the search method is called
as it should be. The only, but very important, thing that I don't understand
is why a button click causes a postback two times - causing the search
method to be called two times??

Hope that you are able to help.

Thank You for your time.

Best regards Torben Jensen
Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.