In this article I will explain how to get the value of the HTML Input TextBox in ASP.Net code behind using C# and VB.Net.
There are two ways we can access the HTML Input TextBox value in ASP.Net code behind
1. Using Request Form collection and name property.
2. Using runat = “server” property.
 
HTML Markup
The HTML Markup consists of a Form consisting of two HTML TextBoxes and a Button of which one TextBox uses name property while other uses runat = “server” property.
<form id="form1" runat="server">
    Name:
    <input type="text" id="txtName" name="Name" value="" />
    <br />
    Email:
    <input type="text" id="txtEmail" runat="server" value="" />
    <br />
    <br />
    <asp:Button Text="Submit" runat="server" OnClick="Submit" />
</form>
 
 
Get value of HTML Input TextBox in ASP.Net code behind
Following is the Button Click event handler inside which values of both the HTML Input TextBoxes are being accessed.
The value of the Name TextBox is being fetched using its name and the Request.Form collection and the value of the Email TextBox is fetched directly using the Value property.
C#
protected void Submit(object sender, EventArgs e)
{
    string name = Request.Form["Name"];
    string email = txtEmail.Value;
}
 
VB.Net
Protected Sub Submit(sender As Object, e As EventArgs)
    Dim name As String = Request.Form("Name")
    Dim email As String = txtEmail.Value
End Sub
 
The following screenshot displays the values of both the TextBoxes being fetched.
Get value of HTML Input TextBox in ASP.Net code behind using C# and VB.Net
 
 
Demo
 
Downloads