简体   繁体   English

回传后将焦点放在html控件上

[英]set focus on the an html control after postback

I am using a form in ASP.NET where dropdownlists cause postback. 我在ASP.NET中使用表单,其中下拉列表导致回发。 I want to set focus back to a specific textbox control after postback occurs. 我想在发生回发后将焦点设置回特定的文本框控件。

I tried calling 我尝试打电话

SetFocus(TextBox1.ID)

but my focus is not changing. 但我的重点没有改变。 I called this function in Page_Load. 我在Page_Load中调用了此函数。 I ran the app in debug mode and verified that TextBox1 is not null and refers to the correct textbox. 我在调试模式下运行了该应用程序,并验证了TextBox1不为null并引用了正确的文本框。

By the way TextBox1 is an html control. 顺便说一下,TextBox1是一个html控件。 Here is the markup 这是标记

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

Here is the dropdownlist that causes postback 这是导致回发的下拉列表

    <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>

I just want to set focus to my textbox. 我只想将焦点设置在我的文本框中。 How to do this? 这个怎么做?

put it inside the callback method like this 放在这样的回调方法中

protected void dropdown_financer_SelectedIndexChanged(object sender, EventArgs e)
{
   // other codes

   TextBox1.Focus();
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM