Aidan Garnish
MOSS 2007 and other Microsoft technologies

Hit enter, fire a web part event the easy way

January 11, 2008 10:33 by Aidan

I have a custom web part search box that has a button next to it that directs the user to the search results page for the query that has been entered. What I also want to do is have that same code fire when the user presses enter. With the asp:textbox control this didn't look as if it was going to be very simple as the text changed event does not fire on every key press. Instead it fires when the control loses focus. 

Fortunately pressing enter causes the control to lose focus so it turns out that it is simple as calling the executequery method in the text changed event like this:

 void txtSearch_TextChanged(object sender, EventArgs e)
        {
              btnExecuteQuery_OnClick(this, e);
        }

Now, whenever a user hits enter the execute query event fires. Testing shows that clicking away from the textbox on a link or tabbing away from the textbox does not fire the event. Result!


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: MOSS 2007
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Related posts

Comments

January 11. 2008 15:55

You sound like you know what you're doing...so I'm going to give you a challenge that even some of the Microsoft 'Experts' haven't been able to answer. We have SharePoint and Business Portal and when I added a Page Viewer web part, I wanted it to automatically show a user's program icons that are currently on their desktop. This would allow them to work from within the home page. It originally worked, but since we've upgraded some of the PC's to XP, the web part no longer shows the icons. I have since figured out that if I start the path with the computer's name, that that will finally work. However, I need the syntax for the path to figure out the current user's computer name and computer profile name.
Here's an example of what I currently have: \\mycomputersname\c$\Document and Settings\usersname\Desktop. Of course, if I fill in my actual computer's name and my own profile name, then my icons appear.
Thanks for reading, even if you can't help--
Kathy--

Kathy

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

January 6. 2009 15:18