HTML forms are frequently used for getting input from the users. You can fill in different form fields containing Checkbox, Text, Radio, and Submit button for input. You can create or fill-in the HTML form programmatically using the C# language. This article covers the following sections related to HTML forms:
- Create or Fill HTML Form - C# API Installation
- Create an HTML Form Programmatically using C#
- Fill HTML Form with Submit Button in C#
- Free API License
Create or Fill HTML Form - C# API Installation
Aspose.HTML for .NET API lets you create or fill HTML forms with Submit buttons programmatically using C# language. You can configure the API by downloading a DLL file from the Downloads section, or quickly install it with the following NuGet installation command:
PM> Install-Package Aspose.Html
Create an HTML Form Programmatically using C#
You can create a HTML form programmatically using C# language. Please follow the steps below for creating it from scratch:
- Initialize an instance of HTMLDocument class.
- Create new HTML form with CreateNew method.
- Input simple text type field.
- Create a radio button input element.
- Input submit button in HTML form and add current nodes.
- Save HTML form.
The following code shows how to create a HTML form programmatically using C#:
Moreover, below is another approach for creating HTML form using native HTML form element in C#:
The following screenshot shows the output HTML form created with above code snippet:
Fill HTML Form with Submit Button in C#
You have already explored how to create an HTML form. Now you can learn how to fill HTML form and send the data to any remote server directly from your C# application. You can iterate through different items in the form and then use Submit button for sending the data. Here you will be working with a template form created by httpbin.org. It includes filling Text, Radio buttons, as well as Checkboxes that you be learning below:
Select the Value in Input Type Checkbox
Checkboxes are helpful where you need to choose more than one option. You can easily select the value in input type checkbox with the following code:
Fill the Input Type Text and Radio Field
An HTML form may contain several text boxes and radio button fields for collecting data. You can fill the input text with the following code:
Likewise, you can select radio button fields with the code below:
Sending Data with Submit Button in HTML
You can send filled data in HTML form with the Submit button using FormSubmitter class. The following code shows how to call Submit() method in C# code:
Source Code
Below is the complete source code to fill HTML forms programmatically using C#:
Free API License
You can evaluate Aspose.HTML for .NET API without any Evaluation Limitations by requesting a Free Temporary License.
Conclusion
In conclusion, you have learned how to create an HTML form from scratch, as well as how to fill an existing HTML form and sending the data to a remote server from your C# application. You can also visit the Documentation section to explore several other features. Please feel free to contact us at the Free Support Forum for any of your queries.