Focus adjustment with ASP.NET AJAX Control Toolkit

I use the AutoComplete ASP.NET AJAX Control Toolkit and I run into a problem when autocomplete doesn't fill when I focus on the assigned text box.

I tried to set focus in the Page_Load, Page_PreRender, and Page_Init events, and the focus is set correctly, but autocomplete does not work. If I do not set the focus, everything works fine, but I would like to set it so that users do not have this extra click.

Is there any special place to set focus or something else that I need to do to make this work? Thanks.

+5
source share
5 answers

. script , , . ( ) : http://www.drive.com.au

MainSearchBox_SearchTextBox. 586, , ( .

var textBoxHasFocus true, false. script:

if (textBoxHasFocus) {
    $get("MainSearchBox_SearchTextBox").blur();
    $get("MainSearchBox_SearchTextBox").focus();
}  

. , ,

+3

,

,

controlId.focus(); # controlID.focus() VB

button_click.

. panel1.focus(); 1 ,

+1

? , , :

Public Sub SetFocus(ByVal ctrl As Control)
    Dim sb As New System.Text.StringBuilder
    Dim p As Control
    p = ctrl.Parent
    While (Not (p.GetType() Is GetType(System.Web.UI.HtmlControls.HtmlForm)))
        p = p.Parent
    End While
    With sb
        .Append("<script language='JavaScript'>")
        .Append("function SetFocus()")
        .Append("{")
        .Append("document.")
        .Append(p.ClientID)
        .Append("['")
        .Append(ctrl.UniqueID)
        .Append("'].focus();")
        .Append("}")
        .Append("window.onload = SetFocus;")
        .Append("")
        .Append("</script")
        .Append(">")
    End With
    ctrl.Page.RegisterClientScriptBlock("SetFocus", sb.ToString())
End Sub

, , , , , .

0

, clientide script, setFocusTimeout codebehind. , , , (setFocus). , , , , AJAX .

function setFocusTimeout(controlID) {
    focusControlID = controlID;
    setTimeout("setFocus(focusControlID)", 100);
}

function setFocus() {
    document.getElementById(focusControlID).focus();
}
0

Glenn Slaven Kris/Alex, , ASP.NET TextBox, AutoCompleteExtender. Document.getElementById(focusControlID).focus() javascript, , document.getElementById . focusControlID ClientID TextBox. - document.getElementById .

, jQuery , , , , Enter , .

setFocus :

function setFocus(focusControlID) {
    $('#' + focusControlID).blur();
    $('#' + focusControlID).focus();
}

javascript, TextBox . , , , , . , , UX.

- 100 300. ...

I agree with everyone that this is a hack. But from the point of view of the end user, they do not see this code. Hacking for them is if they need to manually click inside the control, and not just automatically fit inside the control and enter the first few letters to start the automatic search function. So, the hats of everyone who provided their hacks.

Hope this helps someone else.

0
source

All Articles