Control.Focus Control.Focus Control.Focus Control.Focus Method

定義

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

public:
 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. 如果頁面不包含控制項之 HTMLID符合控制項的屬性,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.

適用於

另請參閱