locked
Set focus to first column on insert RRS feed

  • Question

  • User-1026557788 posted

    Hi,

    I want to set the keyboard focus to the first column of a new entry. Any Ideas?

    Best regards

    Sven

    Wednesday, August 3, 2011 12:26 PM

Answers

  • User-330204900 posted

    Hi , I use thsi extension method:

    public static class ControlExtensionMethods
    {
        /// <summary>
        /// Makes sure focus is still on this control after update.
        /// </summary>
        /// <param name="webControl">The web control.</param>
        public static void SetFocusHere(this WebControl webControl)
        {
            // get reference to the pages script manager
            var scriptManagerRef = ScriptManager.GetCurrent(webControl.Page);
    
            // set focus to the passed in web control
            if (scriptManagerRef.EnablePartialRendering)
                scriptManagerRef.SetFocus(webControl);
            else
                webControl.Page.SetFocus(webControl);
        }
    }

    Like this

    Page.SetFocus(webControl);

    Obvously you need to do this in the field template and you need to tell the the field template that it is the one that should be selected initially I would do this using an custom attribute in the mets model.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2011 1:53 PM

All replies

  • User-330204900 posted

    Hi , I use thsi extension method:

    public static class ControlExtensionMethods
    {
        /// <summary>
        /// Makes sure focus is still on this control after update.
        /// </summary>
        /// <param name="webControl">The web control.</param>
        public static void SetFocusHere(this WebControl webControl)
        {
            // get reference to the pages script manager
            var scriptManagerRef = ScriptManager.GetCurrent(webControl.Page);
    
            // set focus to the passed in web control
            if (scriptManagerRef.EnablePartialRendering)
                scriptManagerRef.SetFocus(webControl);
            else
                webControl.Page.SetFocus(webControl);
        }
    }

    Like this

    Page.SetFocus(webControl);

    Obvously you need to do this in the field template and you need to tell the the field template that it is the one that should be selected initially I would do this using an custom attribute in the mets model.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2011 1:53 PM
  • User-1026557788 posted
    Good idea! I will try that! Thanks! Sven
    Wednesday, August 3, 2011 2:17 PM