AutoPostback 未正确设置焦点

发布于 2024-10-09 18:43:51 字数 3362 浏览 0 评论 0原文

我有一个页面,当自动或部分回发发生时,焦点设置到地址栏而不是下一个控件。有趣的是,当我在 RadScriptBlock 中放置警报时,单击“确定”后,焦点将转到正确的控件 - 或者 - 如果我放置在无效位置,焦点将返回到 ExpLocation 控件 &当第二次输入正确的位置时,Tab 键顺序/焦点命令可以正常工作(请参见下面的代码)。

上面有这个 那个

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxPanel1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting EventName="OnTextChanged" AjaxControlID="RadNumericTextBox_GLm">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadNumericTextBox_GLm" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="lblGlCodeErrorMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting EventName="OnTextChanged" AjaxControlID="RadNumericTextBox_ExpLocation">
            <UpdatedControls>
               <telerik:AjaxUpdatedControl ControlID="lblGlCodeErrorMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="RadNumericTextBox_ExpLocation" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

有这个控制..

<telerik:RadNumericTextBox ID="RadNumericTextBox_ExpLocation" runat="server" Width="20px" AutoPostBack="true"
MaxLength="3" NumberFormat-AllowRounding="False" Type="Number" NumberFormat-KeepTrailingZerosOnFocus="True"
IncrementSettings-InterceptMouseWheel="false" OnTextChanged="LocationCheck_OnTextChanged" TabIndex="101">
<NumberFormat DecimalDigits="0" GroupSeparator="" AllowRounding="false" KeepNotRoundedValue="false" />

后面有这段代码

    protected void LocationCheck_OnTextChanged(object sender, System.EventArgs e)
{
    var cmdText = "SELECT LMLOC FROM DBMOTO..XALOCNP WHERE  " +
            " LMLOC = @ExpLocation ";
        using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MAINConnectionString"].ToString()))
        using (var cmd = new SqlCommand(cmdText, conn))
        {
            cmd.Parameters.Add(new SqlParameter("@ExpLocation", RadNumericTextBox_ExpLocation.Text));
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                Session["ValidGL"] = false;
                lblGlCodeErrorMessage.Visible = false;
                lblGlCodeErrorMessage.Text = "Good Location";
                btnAddItem.Enabled = false;
                btnDone.Enabled = false;
                RadNumericTextBox_GLm.Focus();
            }
            else
            {
                lblGlCodeErrorMessage.Visible = true;
                lblGlCodeErrorMessage.Text = "Invalid/Inactive Location";
                btnAddItem.Enabled = false;
                btnDone.Enabled = false;
                RadNumericTextBox_ExpLocation.Focus();
            }
        }
}

I have a page that when auto or partial post back happens, focus is set to the address bar rather than the next control. The interesting thing is that when I put an alert in my RadScriptBlock, after the OK is clicked, focus goes to the correct control -or- if I put in an invalid location, focus is returned to the ExpLocation control & when a correct location is input the second time, the tab order/focus command works correctly (see code below).

That has this up top

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxPanel1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting EventName="OnTextChanged" AjaxControlID="RadNumericTextBox_GLm">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadNumericTextBox_GLm" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="lblGlCodeErrorMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting EventName="OnTextChanged" AjaxControlID="RadNumericTextBox_ExpLocation">
            <UpdatedControls>
               <telerik:AjaxUpdatedControl ControlID="lblGlCodeErrorMessage" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="RadNumericTextBox_ExpLocation" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

That has this control..

<telerik:RadNumericTextBox ID="RadNumericTextBox_ExpLocation" runat="server" Width="20px" AutoPostBack="true"
MaxLength="3" NumberFormat-AllowRounding="False" Type="Number" NumberFormat-KeepTrailingZerosOnFocus="True"
IncrementSettings-InterceptMouseWheel="false" OnTextChanged="LocationCheck_OnTextChanged" TabIndex="101">
<NumberFormat DecimalDigits="0" GroupSeparator="" AllowRounding="false" KeepNotRoundedValue="false" />

with this code behind

    protected void LocationCheck_OnTextChanged(object sender, System.EventArgs e)
{
    var cmdText = "SELECT LMLOC FROM DBMOTO..XALOCNP WHERE  " +
            " LMLOC = @ExpLocation ";
        using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MAINConnectionString"].ToString()))
        using (var cmd = new SqlCommand(cmdText, conn))
        {
            cmd.Parameters.Add(new SqlParameter("@ExpLocation", RadNumericTextBox_ExpLocation.Text));
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                Session["ValidGL"] = false;
                lblGlCodeErrorMessage.Visible = false;
                lblGlCodeErrorMessage.Text = "Good Location";
                btnAddItem.Enabled = false;
                btnDone.Enabled = false;
                RadNumericTextBox_GLm.Focus();
            }
            else
            {
                lblGlCodeErrorMessage.Visible = true;
                lblGlCodeErrorMessage.Text = "Invalid/Inactive Location";
                btnAddItem.Enabled = false;
                btnDone.Enabled = false;
                RadNumericTextBox_ExpLocation.Focus();
            }
        }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以歌曲疗慰 2024-10-16 18:43:51

尝试使用ScriptManager方法设置焦点并禁用ajax,排查异常是否与ajax相关。 此现场演示使用了这两种技术,并且可以顺便说一句,你的参考点。

Try to set the focus using the ScriptManager method and disable the ajax to troubleshoot whether the abnormality is related to the ajaxification. This live demo uses both techniques and can be your reference point btw.

夏末 2024-10-16 18:43:51

您是否尝试过使用 RadAjaxManager 的 FocusControl 方法,或以下技术之一: http:// /www.telerik.com/help/aspnet-ajax/input_commonfocus.html

Have you tried the FocusControl method using the RadAjaxManager, or one of these techniques: http://www.telerik.com/help/aspnet-ajax/input_commonfocus.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文