I have a series of controls on a page, including some textboxes that serve to record employee timesheet. When OnTextChanged fires, the page postback and update the overall working hours and minutes.
The problem is, when the user clicks the save button, a postback happens, but it is not because of save button's action but because OnTextChanged has fired. The user believes that the saving has gone well until he/she access the page again and doesn't find his/her data. It's next to the impossible to explain to user that they need to click twice because the first time the textbox loses focus and the second time it's the right one.
Is there a way to store the value of the last element that had the focus before the postback occured? I've tried to access the value of __LASTFOCUS, but I'm getting an empty string.
string lastFocus = Page.Request.Params.Get("__LASTFOCUS");
Thanks for helping
I have a similar situation with a GridView with an arbitrary amount of textboxes, each with AutoPostBack on and OnTextChanged event handlers. What I wanted to do was be able to tab out of a textbox, postback, then restore focus to the textbox that had focus before postback e.g. the textbox that I tabbed to.
This is what I ended up with:
The postbackFocusID is just an asp:HiddenField.
If you are trying to grab the last control that lost focus which has AutoPostBack="true", I believe you can get the Name of this control from
Request.Form.Get("__EVENTTARGET")
. This form variable contains the ID of any control invoking postback (in most, if not all, scenarios).