realtek
realtek

Reputation: 841

Set textarea value with HtmlAgilityPack

I am using HtmlAgilityPack and it seems I cannot set the value of the text in a textarea in the same way as an input field:

var node = doc.DocumentNode.SelectSingleNode("//textarea");
if (node != null)
{
    node.SetAttributeValue("value", record.Data);
}

Does anyone know how this can be done?

Upvotes: 2

Views: 2558

Answers (1)

Amit
Amit

Reputation: 46351

A <textarea> element doesn't have a value attribute. It's content is it's own text node:

<textarea>
Some content
</textarea>

To access that, use the .InnerHtml property:

var node = doc.DocumentNode.SelectSingleNode("//textarea");
if (node != null)
{
    node.InnerHtml = record.Data;
}

Upvotes: 2

Related Questions