【问题标题】:set the focus to a textbox with a htmleditorextendor inside an update panel将焦点设置到更新面板内带有 htmleditorextendor 的文本框
【发布时间】:2013-08-19 12:35:31
【问题描述】:

我有一个附加到 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:我将焦点设置到文本框中当前存在的文本的末尾非常重要(文本框加载了数据库中的数据)

【问题讨论】:

    标签: c# asp.net updatepanel datalist htmleditorextender


    【解决方案1】:

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

    例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多