Error:Control 'txtLastName' of type 'TextBox' must be placed

Jul 6 2015 5:56 AM
how to solve bellow maintain error
 
 Error:Control 'txtLastName' of type 'TextBox' must be placed inside a form tag with runat=server.
  
 in asp.net
 
my registration.aspx page code is bellow
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form>
<table>
<tr>
<td>First Name:</td>
<td><asp:TextBox ID="txtFirstName" runat="server">
</asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="rfvFirstName"
runat="server"
ControlToValidate="txtFirstName"
ErrorMessage="First Name can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td><asp:TextBox ID="txtLastName" runat="server">
</asp:TextBox></td>
<td><asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtLastName"
ErrorMessage="Last Name can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td>UserName:</td>
<td><asp:TextBox ID="txtUserName" runat="server">
</asp:TextBox>
</td>
<td><asp:RequiredFieldValidator
ID="rfvUserName"
runat="server"
ControlToValidate="txtUserName"
ErrorMessage="UserName can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td>Password:</td>
<td><asp:TextBox ID="txtPwd" runat="server"
TextMode="Password">
</asp:TextBox>
</td>
<td><asp:RequiredFieldValidator ID="rfvPwd"
runat="server" ControlToValidate="txtPwd"
ErrorMessage="Password can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td>Confirm Password:</td>
<td><asp:TextBox ID="txtRePwd" runat="server"
TextMode="Password">
</asp:TextBox>
</td>
<td><asp:CompareValidator ID="CompareValidator1"
runat="server"
ControlToCompare="txtRePwd"
ControlToValidate="txtPwd"
Operator="Equal"
ErrorMessage="Password and confirm password do not match"
SetFocusOnError="True">
</asp:CompareValidator>
</td></tr>
<tr><td>Gender:</td>
<td><asp:RadioButtonList ID="rdoGender"
runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList>
</td>
<td><asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="rdoGender"
ErrorMessage="Gender can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td>Address:</td>
<td><asp:TextBox ID="txtAdress" runat="server"
TextMode="MultiLine">
</asp:TextBox>
</td>
<td><asp:RequiredFieldValidator ID="rfvAddress"
runat="server"
ControlToValidate="txtAdress"
ErrorMessage="Address can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td>Email ID:</td>
<td><asp:TextBox ID="txtEmailID" runat="server">
</asp:TextBox>
</td>
<td><asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ControlToValidate="txtEmailID"
ErrorMessage="Email can't be left blank"
SetFocusOnError="True">*
</asp:RequiredFieldValidator>
</td></tr>
<tr><td><asp:Label ID="lblMsg" runat="server">
</asp:Label>
</td>
<td><asp:ValidationSummary ID="ValidationSummary1"
runat="server" ShowMessageBox="True"
ShowSummary="False"/>
</td></tr>
<tr><td><asp:Button ID="btnSave" runat="server"
Text="Sign Up"
onclick="btnSave_Click"/>
</td></tr>
</table>
</form>
</body>
</html>
 
 
and
 
my registration.aspx.cs page code is bellow
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace csvfileupload2
{
public partial class registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
//Create ConnectionString and Inser Statement
string connectionString = ConfigurationManager.ConnectionStrings["Data Source=ANIRUDDHA-PC;Initial Catalog=sark;Integrated Security=True"].ConnectionString;
string insertSql = "INSERT INTO Users (FirstName,LastName,UserName,Password,Email,Address,Gender)"
+ " values (@FirstName,@LastName,@UserName,@Password,@Email,@Address,@Gender)";
//Create SQL connection
SqlConnection con = new SqlConnection(connectionString);
//Create SQL Command And Sql Parameters
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = insertSql;
SqlParameter firstName = new SqlParameter("@FirstName", SqlDbType.VarChar, 50);
firstName.Value = txtFirstName.Text.ToString();
cmd.Parameters.Add(firstName);
SqlParameter lastName = new SqlParameter("@LastName", SqlDbType.VarChar, 50);
lastName.Value = txtLastName.Text.ToString();
cmd.Parameters.Add(lastName);
SqlParameter userName = new SqlParameter("@UserName", SqlDbType.VarChar, 50);
userName.Value = txtUserName.Text.ToString();
cmd.Parameters.Add(userName);
SqlParameter pwd = new SqlParameter("@Password", SqlDbType.VarChar, 50);
pwd.Value = txtPwd.Text.ToString();
cmd.Parameters.Add(pwd);
SqlParameter email = new SqlParameter("@Email", SqlDbType.VarChar, 50);
email.Value = txtEmailID.Text.ToString();
cmd.Parameters.Add(email);
SqlParameter address = new SqlParameter("@Address", SqlDbType.VarChar, 50);
address.Value = txtAdress.Text.ToString();
cmd.Parameters.Add(address);
SqlParameter gender = new SqlParameter("@Gender", SqlDbType.VarChar, 10);
gender.Value = rdoGender.SelectedItem.ToString();
cmd.Parameters.Add(gender);
try
{
con.Open();
cmd.ExecuteNonQuery();
lblMsg.Text = "User Registration successful";
}
catch (SqlException ex)
{
string errorMessage = "Error in registering user";
errorMessage += ex.Message;
throw new Exception(errorMessage);
}
finally
{
con.Close();
}
}
}
}
 
please help me 
 
 
 

Answers (6)