ASP.NET:找出哪一个元素有回发之前重点是什么? [英] ASP.NET: Find which element had focus before postback?

查看:87
本文介绍了ASP.NET:找出哪一个元素有回发之前重点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面上的一系列的控制,包括一些文本框,供应记录员工的时间表。当 OnTextChanged 火灾,页面回发和更新整个工作小时和分钟。

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.

问题是,当用户点击保存按钮,回发发生,但它是不是因为 保存按钮的行动,但因为OnTextChanged已经解雇了。用户认为,减排进展顺利,直到他/她再次访问该页面,并没有找到他/她的数据。它的旁边不可能解释给用户,他们需要点击两次,因为第一次文本框失去焦点,第二次它是正确的。

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.

是否有存储有回发前的焦点发生的最后一个元素的值的方法吗?我试图访问的值的 __ LASTFOCUS ,但我得到一个空字符串。

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"); 

感谢您的帮助。

推荐答案

如果你正在试图抓住失去它具有焦点的最后一个控件的AutoPostBack =true时,我相信你可以从<获取该控件的名称code> Request.Form.Get(__ EVENTTARGET)。这种形式的变量包含任何控件调用回发的ID(在大多数,如果不是全部,场景)。

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).

这篇关于ASP.NET:找出哪一个元素有回发之前重点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆