AutoPostback未正确设置焦点

时间:2010-12-29 18:47:35

标签: c# javascript asp.net telerik

我有一个页面,当发生自动或部分回发时,焦点设置为地址栏而不是下一个控件。有趣的是,当我在我的RadScriptBlock中发出警报时,单击OK后,焦点转到正确的控件 - 或者 - 如果我放入一个无效的位置,焦点将返回到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();
            }
        }
}

2 个答案:

答案 0 :(得分:1)

您是否使用RadAjaxManager或其中一种技术尝试了FocusControl方法:http://www.telerik.com/help/aspnet-ajax/input_commonfocus.html

答案 1 :(得分:1)

尝试使用ScriptManager方法设置焦点并禁用ajax以排除异常是否与ajaxification有关。 This live demo使用这两种技术,可以作为你的参考点btw。