我正在使用 ASP.NET 2.0 和 VB.NET(C# 代码也可以帮助我)
在我的页面顶部,我有一个名为 btnViewRecords 的按钮。当用户单击按钮时,我想将焦点设置到同一页面上更下方的另一个按钮或标签。如何才能做到这一点。
这段代码对我不起作用................................
btnTheRecords.Focus()
或
lblHeader.Focus()
提前致谢!
编辑: 即使我的代码确实有效,我也不想每次都重新加载页面。
最佳答案
这是一个相对简单的解决方案...
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return SetFocus()" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<script type="text/javascript">
function SetFocus() {
document.getElementById('<%=TextBox2.ClientID %>').focus();
//or this if you're using jQuery
//$("#<%=TextBox2.ClientID %>").focus();
return false;
}
</script>
关于c# - 通过单击按钮将焦点设置到另一个控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1470816/