This project has moved. For the latest updates, please go here.

Trouble adding to value attribute of input controls

Topics: User Forum
Aug 27, 2006 at 2:13 AM
Hi Simon,

I've been working on an app using the HTMLAgilityPack to download a page, fill data into the value attribute's of an input control, and then resubmit the page. I'm getting errors when I try to assign values to the value attribute of input controls of the HTML page I grab. A piece of the code I'm using is below:

HtmlNodeCollection inputControls = singleFormNode.SelectNodes(".//input | .//select | .//textarea | .//button");

//Loop through each input control found
foreach(HtmlNode inputControl in inputControls)
//Check for a type attribute
if (inputControl.Attributes"type" != null)
//Give the control a value if it's of type "text"
if (inputControl.Attributes"type".Value.Equals("text") && inputControl.Attributes"value" != null)

-----> ERROR is seen on the assignment below
inputControl.Attributes"value".Value = "test";

If I comment out the line above that gives the error, the code correctly grabs the page and outputs all the input controls with associated information. Any idea what the problem is? Thanks!
Sep 1, 2006 at 8:58 PM
What kind of error do you get? Compile error? Runtime error? Please copy/paste the details.

(alternatively, you can use Node.SetAttributeValue to set attributes' value)