gpt4 book ai didi

c# - SetFocus 只能在 PreRender 之前和期间调用

转载 作者:行者123 更新时间:2023-11-30 17:09:41 30 4
gpt4 key购买 nike

谁能告诉我为什么我会在下面的跟踪中收到错误?

“SetFocus 只能在 PreRender 之前和期间调用。”

错误消息表明必须在 PreRender 之前或期间调用“SetFocus”,并且根据跟踪结果,页面与 PreRender 几乎没有任何关系。

那么为什么会出错呢?

从 Trace.axd 复制...

Begin PreInitEnd PreInitBegin InitEnd InitBegin InitCompleteEnd InitCompleteBegin LoadStateEnd LoadStateBegin ProcessPostDataEnd ProcessPostDataBegin PreLoadEnd PreLoadBegin LoadEnd LoadBegin ProcessPostData Second TryEnd ProcessPostData Second TryBegin Raise ChangedEventsEnd Raise ChangedEventsBegin Raise PostBackEventSetFocus can only be called before and during PreRender.  at System.Web.UI.Page.SetFocus(Control control)  at System.Web.UI.Control.Focus()  at ....ShowChangePasswordPopup(RecruiterClass recruiter, String commandName) in C:\...\RecruiterPopups.ascx.cs:line 1134  at ....Default.Password_OnBeforeGo(MenuItem item, String queryString, Boolean forceRedirect) in C:\...\Default.Master.cs:line 92  at ....MenuItem.GoDelegate.Invoke(MenuItem item, String queryString, Boolean forceRedirect)  at ....MenuItem.Go(String queryString, Boolean forceRedirect) in C:\...\Menu\MenuItem.cs:line 129  at ....MenuItem.Go() in C:\...\Menu\MenuItem.cs:line 115  at ....MainMenu.lnkMyAccountProfilePassword_Click(Object sender, EventArgs e) in C:\...\UserControls\MainMenu.ascx.cs:line 130  at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)  at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)  at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)  at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)  at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

最佳答案

在正在回发的页面上调用 SetFocus() 并导致重定向到另一个页面将导致此错误。尝试仅在 !Page.IsPostBack 时调用 Focus/SetFocus,您会发现错误将不再发生。

关于c# - SetFocus 只能在 PreRender 之前和期间调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12750403/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com