[英]How do clear/set value of Asp.Net TextBox that has an Ajax Control Toolkit HTML Editor Extender from the client?
I'm using ACT 4.1.7.607. 我正在使用ACT 4.1.7.607。 Client is IE 9. 客户端是IE 9。
I can not find a solution where I can clear the contents of the editor from the client. 我找不到可以从客户端清除编辑器内容的解决方案。
I have tried using JQuery: 我试过使用JQuery:
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" height="200px" Width="837px"></asp:TextBox>
<ajaxToolkit:HtmlEditorExtender ID="htmlEditorExtender" TargetControlID="TextBox1" runat="server" EnableSanitization="False"></ajaxToolkit:HtmlEditorExtender>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
<asp:Button ID="Button2" runat="server" Text="Clear" />
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#<%=Button2.ClientID%>').click(function () {
var editorControl = $get("<%=TextBox1.ClientID%>");
var clearValue = '';
editorControl.innerHTML = clearValue;
})
})
</script>
This seems to change the innerHTML value of the textbox. 这似乎改变了文本框的innerHTML值。 However, the screen does not update to show the change. 但是,屏幕不会更新以显示更改。
Have also tried JavaScript: 还尝试过JavaScript:
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" height="200px" Width="837px"></asp:TextBox>
<ajaxToolkit:HtmlEditorExtender ID="htmlEditorExtender" TargetControlID="TextBox1" runat="server" EnableSanitization="False"></ajaxToolkit:HtmlEditorExtender>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
<asp:Button ID="Button2" runat="server" Text="Clear" OnClientClick="javascript:clearEditor()" />
<script type="text/javascript" language="javascript">
function clearEditor(){
document..getElementById('<%=TextBox1.ClientID%>').innerHTML = '';
}
</script>
This also seems to change the innerHTML value, but, again it does not show the change in browser window. 这似乎也改变了innerHTML的值,但是,它再次没有显示浏览器窗口中的变化。
I have seen 'solutions' that speak of div containers for the extender or the 'ExtenderContentEditable' attribute of the extender or the 'setContent' method of the extender - none of these exist in my world. 我已经看到“解决方案”,它涉及扩展程序的div容器,扩展程序的“ ExtenderContentEditable”属性或扩展程序的“ setContent”方法-在我的世界中,这些都不存在。
If there is a solution to this, I would be most grateful to see it. 如果有解决方案,我将不胜感激。
You can use this script: 您可以使用以下脚本:
function clearHtmlExtender(){
var extender = $find("<%= htmlEditorExtender.ClientID %>");
extender._editableDiv.innerHTML = "";
extender._editableDiv_onblur();
}
The short description: script above resetting content of editable div (_editableDiv.innerHTML) and then force extender to assign this hrml to target textbox. 简短说明:上面的脚本重置可编辑div(_editableDiv.innerHTML)的内容,然后强制扩展程序将此hrml分配给目标文本框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.