SearchForm triggers postback 2 times?

  • Thread starter Torben Philippsen
  • Start date
T

Torben Philippsen

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
 
T

Torben Philippsen

Marina said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top