postback problem

  • Thread starter Thread starter Alessandro
  • Start date Start date
A

Alessandro

Hi !

I have a aspx page with these controls:

1) a texbox to find person with a specific name....
2) a button nto perform the search
3) a datagrid tho show all user

If i have the focus on the texbox and i click enter i have a
postback.............. but i dont' want it, because the datagrid doesn't
bind correctly... i must click on the button to do the postback......

Any idea ?
 
The general cause here is the "default" button is fired, instead of the
button you desire to be hit. For a simple form, try:

Page.RegisterHiddenField( "__EVENTTARGET", "btnSearch" );

Change btnSearch to your button name. That will fire the correct button for
the form.

If you need a particular button for different textboxes, you will have to
move to JavaScript. Try this link for a C# method that writes out the
JavaScript:

http://dotnetjunkies.com/WebLog/darrell.norton/archive/2004/03/03/8374.aspx

It is further culled here:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20944907.html

To disable the enter key, you have to trap that event in JavaScript. I would
not head this direction unless absolutely necessary.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top