AutoPostback not setting focus correctly
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:AjaxUpdated开发者_运维知识库Control 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();
}
}
}
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.
Have you tried the FocusControl method using the RadAjaxManager, or one of these techniques: http://www.telerik.com/help/aspnet-ajax/input_commonfocus.html
精彩评论