Imran,
I saw it right away. You've got your text box set to autopost back on text
changed. So the moment you leave the text box your page posts back and runs
the page load then again for the button click. I believe that your
btnSearch_Click routine is probably being called twice also.
Assuming that you are using the ontextchanged routine to handle if the user
hits the enter key while in the text box there are two ways you can stop
this behaviour:
One would be to stop the button click itself altogether with a javascript
such as: btnSearch.Attributes.Add("onclick", "javascript
: return false;")
but doing so will stop a user from re-running a search by clicking the
button a second time. They would only be able to search when entering new
text in the search text box.
Another way (which is the method I prefer) is to remove autopost back from
the text box and make hitting the enter key while in the text box click the
search button. Do that like this: btnSearch.Attributes.Add("onkeydown",
"javascript
:(if((event.which && event.which == 13) || (event.keyCode &&
event.keyCode == 13)){document.getElementById('" & btnSearch.ClientID &
"').click();return false;}else return true;")
If you'd like I have created a free Javascript component that has many
useful scripts in it. You simply drag it onto the page you want to use it on
(in the designer) and then in the code-behind call any of its methods and
they automatically hook up scripts to the page controls to do things like
click a button when the enter key is hit while in a text box, pop-up a
centered window, add a javascript confirmation window on a button click,
scroll a control into view (replacing smart navigation), stopping a user
from clicking a submit button more than once, etc. You may download the
component as a .NET project with all source code for free from my web site
http://www.aboutfortunte.com just click on the "Code Library" link at the
top of the page and then click the "Javascript" button on the left side of
the page. There is also a full help file for all the components I've
developed and shared.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Imran Aziz" <im***@tb2.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hello All,
I have a search text and button that post data and my button handler
filters the repeater control. However when the button is clicked the first
time. The page_load event is being called twice, once with postback true,
and second time without postback. This only happens for this button. How
can I sort out this issue, any clues what to look for to get this sorted
please.
<p>Search Bookmarks: <asp:TextBox ID="txtSearch" runat="server"
class="texta" OnTextChanged="btnSearch_Click"
AutoPostBack="true"></asp:TextBox><asp:Button ID="btnSearch"
runat="server" class="button" Text="go" OnClick="btnSearch_Click"
UseSubmitBehavior="true" /></p>
Imran.