简体   繁体   English

ASP.NET中的SetFocus()和Focus()有什么区别?

[英]What's the difference between SetFocus() and Focus() in ASP.NET?

I can use both in the code behind: 我可以在后面的代码中使用它们:

SetFocus() - "Sets the browser focus to the specified control." SetFocus() - “将浏览器焦点设置为指定的控件。”

Focus() - "Sets input focus to a control." Focus() - “将输入焦点设置为控件。”

In practice, what's the difference? 在实践中,有什么区别?

Thanks! 谢谢!

Page.SetFocus can accept a control's client ID as a string instead of a reference to the control itself, which may be useful if you can't get a reference to the control to call its Focus method. Page.SetFocus可以接受控件的客户端ID作为字符串而不是对控件本身的引用,如果您无法获得对控件的引用以调用其Focus方法,则这可能很有用。

control.Focus() is identical to Page.SetFocus(control) . control.Focus()Page.SetFocus(control)相同。 In fact, all is does is call SetFocus... 事实上,一切都是调用SetFocus ......

public virtual void Focus()
{
    this.Page.SetFocus(this);
}

From msdn : 来自msdn

To set focus on an ASP.NET Web server control 将焦点设置在ASP.NET Web服务器控件上

Call the control's Focus method. 调用控件的Focus方法。

-or- -要么-

Call the page's SetFocus method, passing it the ID of the control on which you want to set focus. 调用页面的SetFocus方法,向其传递要设置焦点的控件的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET - ChildActionOnly 和 NonAction 属性之间有什么区别? - ASP.NET - What's the difference between ChildActionOnly and NonAction attributes? ASP.NET和C#有什么区别? - What's the difference between ASP.NET and C#? Asp.Net Core中的IRequestCultureFeature和CurrentCulture有什么区别? - What's the difference between IRequestCultureFeature and CurrentCulture in Asp.Net Core? ASP.NET MVC中&lt;%#和&lt;%=有什么区别? - What is the difference between <%# and <%= in ASP.NET MVC? <a href="linkhere">ASP.NET Core</a><a asp-page="linkhere">和</a>in 有什么区别? - What's the difference between <a asp-page="linkhere"> and <a href="linkhere"> in ASP.NET Core? ASP.NET缓存 - 直接赋值与Add()或Insert()之间的区别是什么 - ASP.NET Cache - What's the difference between direct assignments and Add() or Insert() 在ASP.NET Core Web App中,AddJsonOptions和AddJsonFormatters之间的区别是什么? - In an ASP.NET Core Web App, what's the difference between AddJsonOptions and AddJsonFormatters? ASP.NET MVC:Service和Repository之间的概念有何不同 - ASP.NET MVC: What's the difference in concept between Service and Repository 这些在 ASP.NET Core 中启动/运行通用主机的方法有什么区别? - What's the difference between these ways to start/run a Generic Host in ASP.NET Core? WCF Web API和ASP.NET Web API之间有什么区别 - What's the difference between WCF Web API and ASP.NET Web API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM