views:

165

answers:

2

I want to save the contents of a multline textbox when off focus - i.e. user has finished typing and clicks outside the textbox so it goes off focus.

I can handle the saving- thats no problem, but is there an off focus function? I don't mind a javascript version. I must be using asp:TextBox though.

I tried with onFocus, OnServerChange, onKeyUp, but it is not exactly how I want it. If any of you use Facebook, then it is like the textbox displayed right below the profile picture.

+2  A: 

OnBlur :)

<asp:TextBox runat="server" onblur="alert(1);" />

(I can't recall, off the top of my head, if it will write any unknown server property to the client, I think it does, but if it doesn't, you'll need to add it as an attribute, in code).

-- Edit:

Confirmed that it does, indeed, happily write out unknown properties (onblur is not a property of TextBox control, but it will render in the HTML, so it works).

Noon Silk
+1 perfect... damn I saw onBlur but didn't try it, tried every other one though :(.. feel silly asking such as stupid question now. Thanks!
waqasahmed
You're welcome! and I think I went through the exact same process when I was first looking for something like this as well :)
Noon Silk
ASP.NET behavior by default is to render unknown attributes pretty much anywhere they appear. Don't know how it handles attributes like class when both it and CssClass are defined.
David Andres
@DavidAndres: I thought CssClass renders to Class? So won't that just be a case of having two classes defined?
waqasahmed
A: 

A multiline textbox should render to a textarea element. Assign an event handler to its onBlur event, and you should be good.

David Andres