简体   繁体   English

将焦点设置到更新面板中带有htmleditorextendor的文本框

[英]set the focus to a textbox with a htmleditorextendor inside an update panel

i have a textbox attached to a htmleditorextender that is present inside a usercontrol and this user control is present inside a data list control which is in an update panel. 我有一个附加到htmleditorextender的文本框,该文本框存在于用户控件内,并且此用户控件存在于更新面板中的数据列表控件内。 i have a edit link button on click of which the text box is shown and at this time i want to set focus to the text box i have tried doing this. 我有一个编辑链接按钮,单击该按钮会显示该文本框,这时我想将焦点设置为该文本框,我已经尝试过这样做。

 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);
        }
    }

i have also tried getting the texbox and doing .Focus() but its not working is there some way of getting this done. 我也尝试过获取texbox并执行.Focus(),但是它无法正常工作是有某种方法可以完成此操作的。
PS: its very important that i set the focus to the end of the currently present text in the text box (the text boxes are loaded with data from the data base) PS:非常重要的一点是,我将焦点设置到文本框中当前显示的文本的末尾(文本框中加载了数据库中的数据)

Use client side script to focus. 使用客户端脚本进行聚焦。 HtmlEditorExtendor Load many content in page. HtmlEditorExtendor在页面中加载许多内容。 This may cause problem . 这可能会引起问题。 Try to use below jQuery may help you. 尝试在下面使用jQuery可能会帮助您。

Eg: 例如:

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

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

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