1

I've got an asp.net text box (ID = "HTMLTextBox_Comments") with an HTMLEditorExtender:

<asp:TextBox ID="HTMLTextBox_Comments" runat="server" Height="200px" Rows="5" 
        TextMode="MultiLine" Width="469px"></asp:TextBox>
<ajaxToolkit:HtmlEditorExtender ID="HTMLTextBox_Comments_HtmlEditorExtender" 
        runat="server" Enabled="True" TargetControlID="HTMLTextBox_Comments">
</ajaxToolkit:HtmlEditorExtender>

I'm setting the value of the text box with javascript like this:

var MyControl = document.getElementById("MainContent_HTMLTextBox_Comments"); //this gets the control just fine
MyControl.value = "Here's some text";

If I have an alert show me the value, then it displays "Here's some text", but that text is not displayed in the TextBox itself.

I've also tried setting MyControl.innerHTML and MyControl.text but neither of those seem to work either.

How can I display the value of the TextBox in the TextBox?

Thanks in advance!

EDIT I found this post that seems to indicate that .value is what I'm supposed to use to set the text of this TextBox, but it just isn't showing up. What am I missing?

Community
  • 1
  • 1
nickvans
  • 898
  • 13
  • 24

2 Answers2

0

WebForms add a crazy id to your server side elements. try document.querySelector()

http://jsfiddle.net/ZhGX7/

<input type="text" id="abc_123_MyDiv" value="firstValue" />

<script>

var input = document.querySelector("input[id*=MyDiv]");

input.value="Updated Value"
</script>
bluetoft
  • 5,373
  • 2
  • 23
  • 26
  • Great tip that'll save me having to look at the source of the built page to figure out the full name, however I'm not having trouble getting a handle on the control, my problem is that the control isn't displaying the value I set to the control. – nickvans Nov 07 '12 at 19:40
0

I found a solution here.

The trick is to set the innerHTML of the ExtenderContentEditable div within the HTMLEditorExtender rather than trying to set the text box value directly. It's worth noting that setting the innerHTML also sets the value, so you can read TextBox.value and get what you put in.

Thank you for your help.

Community
  • 1
  • 1
nickvans
  • 898
  • 13
  • 24