将焦点设置为一个文本框,该文本框在更新面板中具有一个htmleditorextendor

本文关键字:文本 更新 htmleditorextendor 有一个 具有一 焦点 一个 设置 | 更新日期: 2023-09-27 18:28:16

我有一个文本框,它连接到用户控件中的一个htmleditorextender上,而这个用户控件位于更新面板中的数据列表控件中。我有一个编辑链接按钮,点击后会显示文本框,此时我想将焦点设置为我尝试过的文本框。

 protected void lnkEditResponse_OnCommand(object sender, CommandEventArgs e)
    {
        if (QuestionList.Items.Count == 0)
        {
            log.Warn("There are no items in the data list.");
            return;
        }
        try
        {
            DataListItem item = QuestionList.Items[int.Parse(e.CommandArgument.ToString())];
            if (item == null)
            {
                log.Warn("No item found for the index " + e.CommandArgument);
                return;
            }
            Panel responseLabelPanel = item.FindControl("ResponseLabelPanel") as Panel;
            Panel responseInputPanel = item.FindControl("ResponseInputPanel") as Panel;
            TextBox textArea = item.FindControl("QuestionResponseTextBox") as TextBox;
            responseLabelPanel.Visible = false;
            responseInputPanel.Visible = true;
            ScriptManager mgr = ScriptManager.GetCurrent(this.Page);                                

            (responseInputPanel.FindControl("LinkClearAll") as LinkButton).Visible = true;
            (responseInputPanel.FindControl("lnkClear") as LinkButton).Visible = true;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "f", "document.getElementById('" + textArea.ClientID + "').focus();", true);
        }
        catch (Exception ex)
        {
            log.Error("Exception while handling file delete.", ex);
        }
    }

我也尝试过使用texbox和.Focus(),但它不起作用——有一些方法可以做到这一点
PS:将焦点设置到文本框中当前文本的末尾非常重要(文本框加载了数据库中的数据)

将焦点设置为一个文本框,该文本框在更新面板中具有一个htmleditorextendor

使用客户端脚本进行聚焦。HtmlEditorExtendor在页面中加载许多内容。这可能会造成问题。尝试使用以下jQuery可能会对您有所帮助。

例如:

$('#target').focus();