Control.Focus 方法


設定控制項的輸入焦點。Sets input focus to a control.

 virtual void Focus();
public virtual void Focus ();
abstract member Focus : unit -> unit
override this.Focus : unit -> unit
Public Overridable Sub Focus ()


使用 Focus 方法,將網頁的初始焦點設定為控制項。Use the Focus method to set the initial focus of the Web page to the control. 頁面將會在瀏覽器中開啟,並已選取控制項。The page will be opened in the browser with the control selected.

Focus 方法會導致頁面焦點腳本的呼叫在呈現的頁面上發出。The Focus method causes a call to the page focus script to be emitted on the rendered page. 如果頁面不包含具有 HTML ID 屬性(attribute)的控制項符合 Focus 方法被叫用的控制項,則不會設定頁面焦點。If the page does not contain a control with an HTML ID attribute that matches the control that the Focus method was invoked on, then page focus will not be set. 例如,當您將焦點設定在使用者控制項上,而不是將焦點設定在使用者控制項的子控制項時,就會發生這種情況。An example where this can occur is when you set the focus on a user control instead of setting the focus on a child control of the user control. 在此案例中,您可以使用 FindControl 方法來尋找使用者控制項的子控制項,並叫用它的 Focus 方法。In this scenario, you can use the FindControl method to find the child control of the user control and invoke its Focus method.