Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Sometimes it is necessary to save an HTML document with input form fields filled in. Although browsers don’t allow this for security reasons, Aspose.HTML provides a
SerializeInputValue property of the
HTMLSaveOptions class that gives you this ability. If the HTML document has input fields filled in, using the SerializeInputValue property, you can save the resulting document as it looks in the browser.
This article describes how to serialize input values in HTML forms or input fields using the Aspose.HTML for .NET library.
Some HTML documents contain form elements such as
HTMLInputElement,
HTMLTextAreaElement, and so on. For security reasons, their values are not saved, but you can change the situation using the SerializeInputValue option of the HTMLSaveOptions class. You should follow these required steps:
GetElement* methods of the
Document class to get a required HTML element/elements in the document and use the Value properties (get or set their values).SerializeInputValue property to true.path, saveOptions) method of the HTMLDocument class and pass the file path where you want to save the document and the HTMLSaveOptions instance as parameters.Let’s look at the apply the SerializeInputValue property using an example of an
HTMLInputElement that represents an HTML input element such as a text box. Follow the step-by-step instructions to serialize the input value into a simple HTML form we create from scratch:
content, baseUri) constructor.input elements in the document and store them in the inputElements variable.<input> element, in this case, from the resulting collection and set the
Value property of the
HTMLInputElement class.path, saveOptions) method. Set the
SerializeInputValue property to true on the HTMLSaveOptions object passed as a parameter to the Save() method.Here is an example of how to serialize input values in an input field using Aspose.HTML C# library:
1// Set input value and serialize HTML form element using C#
2
3string html = @"
4<html>
5 <body>
6 <div>The new input element value: <input type = ""text"" value=""No"" /></div>
7 </body>
8</html>";
9
10// Create an HTML document from string of code containing an HTMLInputElement
11using HTMLDocument doc = new HTMLDocument(html, string.Empty);
12
13// Get all elements with the <input> tag
14HTMLCollection inputElements = doc.GetElementsByTagName("input");
15
16// Take the first and only element, in this case, from the resulting collection
17HTMLInputElement input = (HTMLInputElement)inputElements[0];
18
19// Set the desired value for this HTML form element
20input.Value = "Text";
21
22// Prepare a path to save HTML
23string savePath = Path.Combine(OutputDir, "result.html");
24
25// Save the HTML document with SerializeInputValue set to true
26doc.Save(savePath, new HTMLSaveOptions { SerializeInputValue = true });Thus, the
SerializeInputValue property of the HTMLSaveOptions class determines whether the values of input elements in an HTML document are serialized and included in the saved file or not. If SerializeInputValue is true, the input element values will be included in the saved file. If SerializeInputValue is not set, the input element values will not be included in the saved file.
You can download data files and complete C# examples that demonstrate how to set font folder from GitHub.
Aspose.HTML offers free HTML Web Applications, an online collection of converters, mergers, SEO tools, HTML code generators, URL tools, formatters, minifiers, and more. The applications work on any operating system with a web browser and do not require any additional software installation. It’s a fast and easy way to efficiently and effectively solve your HTML-related tasks!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.