.Net中TextBox获得焦点的方法

<html>
    <head>
<title>关中游侠——.Net中TextBox获得焦点的方法</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            .Net中TextBox获得焦点的方法<br />
            <asp:textbox id="txtWords" runat="server" Width="100%" TextMode="MultiLine"></asp:textbox>
            <br />
            更多内容欢迎访问关中游侠的博客:<a href="http://hi.baidu.com/activezfj" title="点击访问" target="_blank">http://hi.baidu.com/activezfj</a>
            <br />
            <!--
                在这里加入脚本
            -->
       </form>
    </body>
</html>

方法一:
        将“在这里加入脚本”替换为:document.Form1.txtWords.focus();

方法二:
        将“在这里加入脚本”替换为:document.getElementById('<%=txtWords.ClientID%>').focus();

方法三:  
  CEdit   *p=(CEdit*)GetDlgItem(编辑框的ID);  
  p.SetFocus();  
方法四:  
  给这个编辑框定义一个CEdit类型的变量,比如m_edit;  
  在需要的地方,用m_edit.SetFocus()就可以了。  
  就可以搞定了

function text_focus() { window.form1.textbox1.focus(); } 在aspx页面中onload_keydown事件中使用该函数

Button1.Attributes.Add("onclick",   "javascript:document.all.kongjianId.focus();")

 

原文地址:https://www.cnblogs.com/0000/p/1601052.html