【问题标题】:set focus on the an html control after postback回发后将焦点设置在 html 控件上
【发布时间】:2014-08-14 03:18:37
【问题描述】:

我在 ASP.NET 中使用下拉列表导致回发的表单。 我想在回发发生后将焦点设置回特定的文本框控件。

我试着打电话

SetFocus(TextBox1.ID)

但我的关注点没有改变。我在 Page_Load 中调用了这个函数。我在调试模式下运行应用程序并验证 TextBox1 不为空并且引用了正确的文本框。

顺便说一句,TextBox1 是一个 html 控件。这是标记

<input type="text" id="TextBox1" runat="server" />

这是导致回发的下拉列表

    <asp:DropDownList ID="dropdown_finance runat="server"
                         OnSelectedIndexChanged="dropdown_financer_SelectedIndexChanged"
                         AutoPostBack="true">

                         <asp:ListItem Selected="True">Father / Husband</asp:ListItem>
                         <asp:ListItem>Mother</asp:ListItem>
                         <asp:ListItem>Specify information of financer</asp:ListItem>
                     </asp:DropDownList>

我只想将焦点设置到我的文本框。如何做到这一点?

【问题讨论】:

    标签: asp.net .net webforms postback


    【解决方案1】:

    像这样放在回调方法中

    protected void dropdown_financer_SelectedIndexChanged(object sender, EventArgs e)
    {
       // other codes
    
       TextBox1.Focus();
    }
    

    【讨论】:

      猜你喜欢
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 1970-01-01
      • 2011-03-21
      • 2011-10-26
      • 2016-10-22
      • 2013-09-01
      相关资源
      最近更新 更多