Asp.net custom onfocus event for textbox

Is it possible to create a custom server side onfocus event for a textbox control?

I would like to just run the server side method when the textbox has focus.

+1


a source to share


5 answers


There is nothing built in there, because focusing the textbox does not cause the page to be submitted. You can always bind the event to focus on the client side and then send some kind of AJAX request to the server, but I'm curious to know what exactly you are trying to achieve here.



+4


a source


I would highly recommend using client side validation for this. You can use ASP.NET validators for this. One of the properties on the validator is to set focus on an error. This should be more than enough for what you are trying to do, and also limits the number of server side calls.

If you're really feeling creative, you might want to look at some of the other validation options and the AJAX Control Panel extension. There are some pretty fun validator validation tools out there. Another option would be to consider using some jQuery validation.



You should still check on the server, but what you are describing seems to be perfect for client validation.

+1


a source


Ok, I got a webform and when validating a submit, if there are errors on the page, those errors are saved in the state and a warning sign is displayed.

Now when the user is viewing the errors, I wanted the popup to appear next to the textbox they are currently fixing.

For this to happen, I wanted to have an event attached to a handle of type onfocus.

0


a source


Is the server side onFocus the correct solution for this? If you want check popups, etc., you are probably better off with a client-side solution. Having a submit form when you just paste into a textbox won't be good usability.

0


a source


You can do this using a custom validator connected to some AJAX call, however you only need to do a server shutdown if the server has data to check against the current data.

0


a source







All Articles