用户控件保留框TextChanged回发后集中的错误,这UC包含在DetailsView控件中 [英] User control retains focus incorrectly after TextChanged postback when UC is contained within a detailsview control

查看:124
本文介绍了用户控件保留框TextChanged回发后集中的错误,这UC包含在DetailsView控件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我引用previous后:<一href=\"https://stackoverflow.com/questions/4583948/focus-lost-on-partial-postback-with-usercontrols-inside-updatepanel/27650018#27650018\">Focus失去了部分回发的UpdatePanel与内部用户控件
其中,一个优秀的解决方案,完全适用于网页控件的窗体中。
不过,我已经把我的UC一个DetailsView模板字段(编辑+插入)内。

在UC中包含一个UpdatePanel需要调整后的UC-文本框(的AutoPostBack =真)编辑模式和DetailsView控件的插入-模式中的TextChanged事件文本格式和控件的样式(S)。

因此​​,当在DetailsView控制处于编辑模式,以及用户在UC改变文本,TextChanged事件被触发,用户输入的值进行验证,当确定,thousounds分隔(逗号)是加入UC-文本框,文本,但是,将焦点移到在DetailsView的下一个领域并迅速返回到UC-控制。

在UC被包裹在的UpdatePanel作为自聚焦引用文章中指出和Tab键顺序的这种不正确的对焦移动(S)不会出现完美的作品DetailsView控件之外。

下面是模板场-EDIT(只)。

的ASPX标记

 &LT; ASP:的TemplateField的HeaderText =初始里程SORTEX pression =IMilage&GT;
&LT;&EditItemTemplate的GT;
&LT; ASP:的UpdatePanel ID =updpnlIMilage=服务器的UpdateMode =条件&GT;
    &LT;&的ContentTemplate GT;
        &LT; TGANumeric:GANumeric ID =ucnumIMileage=服务器
            标题=初始里程HideCaption =真WIDTH =160
            DisplayMask =999,999输入掩码=999999
            启用=真IsRequired =FALSE
            MinNumber =0MAXNUMBER =999999
            文字='&LT;%#绑定(IMilage)%&GT;'
            的TabIndex =0
            /&GT;
    &LT; /&的ContentTemplate GT;
    &LT;&触发器GT;
        &LT; ASP:AsyncPostBackTrigger控件ID =ucnumIMileage/&GT;
    &LT; /触发器&GT;
&LT; / ASP:的UpdatePanel&GT;
&LT; / EditItemTemplate中&GT;

在此先感谢。您的意见是值得欢迎的。
谢谢...,J。


解决方案

根据在这个线程所有的评论,我想解释的跨栏不端行为的实际根本原因。结果
1)无编码的问题或事件的问题与用户控制。

2)无编码的问题或事件的问题与母版页,内容页的层次感,阿贾克斯更新-板/嵌套更新,板,细节视图,并包含用户控件模板字段。

3)真正的罪魁祸首是code的一个小片段,其中以国家的页面/形式的(状态)页面调整的形式在网络上的控件。我管理的可见调整和/或在$ C $单个子程序实现的网络控制C-背后,使这一切启用/禁用可见/不可见在一个地方一组CASE语句的下发生。
code'的内侧sbSetFormState)(实际错误的片段 - 方法与类变量m_eFormState,实际上造成了更新面板重新火,因此跨栏得到抛出顺序搞乱

这是由'fnostro'伟大的建议,删除或添加功能的功能,直到不当行为暴露自身发现的。
我纪念这一问题作为解决/关闭。
再次,感谢fnostro!

I reference a previous post: Focus lost on partial postback with UserControls inside UpdatePanel where an excellent solution works perfectly for web-page controls within a form. However, I have placed my UC inside a detailsview template-field (for Edit+Insert).

The UC contains an UpdatePanel needed to adjust the text-formatting and control's style(s) following the TextChanged event of the UC-textbox (AutoPostback=True) during the Edit-mode and Insert-modes of the DetailsView.

As such, when the DetailsView-control is in Edit-mode, and user changes Text in the UC, the textchanged event is fired and the user-entered value is validated and when OK, the thousounds-separator (comma) are added to the UC-textbox-text, BUT, the focus moves to the next field in the DetailsView and QUICKLY returns back to the UC-control.

This incorrect focus-move(s) does NOT occur when the UC is wrapped in updatepanels as noted in the referenced post since the focus and tabbing order works perfectly outside of the DetailsView control.

Here is the aspx markup for the template-field-EDIT (only).

<asp:TemplateField HeaderText="Initial Mileage" SortExpression="IMilage">
<EditItemTemplate>
<asp:UpdatePanel ID="updpnlIMilage" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
        <TGANumeric:GANumeric ID="ucnumIMileage" runat="server"
            Caption="Initial Mileage" HideCaption="True" Width="160"
            DisplayMask="999,999" InputMask="999999"
            Enabled="True" IsRequired="False"
            MinNumber="0" MaxNumber="999999"
            Text='<%# Bind("IMilage") %>'
            TabIndex="0"
            />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ucnumIMileage" />
    </Triggers>
</asp:UpdatePanel>
</EditItemTemplate>

Thanks in advance. Your comments are welcome. Thanks...J.

解决方案

Based on all the comments in this thread, I want to explain the actual root cause of the tabbing misbehavior.
1) There were no coding issues or event-issues with the user-control.

2) There were no coding issues or event-issues with the layering of Master-page, Content-page, Ajax update-panels / nested update-panels, details-view and template-fields containing the user-control.

3) The real culprit was a small snippet of code where the page adjusts the web-controls on the form based on the "state" (status) of the page/form. I manage the adjusting of visible and/or enabling of web-controls in a single subroutine in the code-behind so that all of this enabling/disabling visible/not-visible occurs in one place under a set of CASE-statements. The actual erroneous snippet of code inside the 'sbSetFormState()'-method was messing with the class-variable 'm_eFormState' that actually caused the update panel to re-fire and thus the tabbing got thrown out of sequence.

This was discovered by the great suggestion from 'fnostro' to remove or add functionality features until the mis-behavior exposes itself. I mark this topic as resolved/closed. Again, thanks to fnostro !!!

这篇关于用户控件保留框TextChanged回发后集中的错误,这UC包含在DetailsView控件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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