11

Is there a way to specify some JavaScript to execute on the OnBlur event of an ASP.NET text box? It seems to me like if I add any event handlers to the TextBox object they will just cause postbacks to the server isntead of doing what I want. Basically, I just want to be able to have the textbox be rendered in this HTML:

<INPUT type="text" onblur="alert('1234')" />

Thanks!

2 Answers 2

12

Could also go for:

<asp:TextBox runat="server" onblur="Javascript:alert('1234');" />

if you dont feel like setting it up in the codebehind.

Im guessing the reason why you end up with postbacks, must be because you have set AutoPostBack on the textbox to true. That makes the textbox postback when the client-side onchange event is triggered. Switch it to false, and it will act as a normal input-element.

Sign up to request clarification or add additional context in comments.

Comments

11

In your codebehind, add this:

myTextBox.Attributes.Add("onblur","alert('1234');");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.