Use one button in your .aspx page and runat server you text box like:
<body>
<form id="form1" runat="server">
<div>
<textbox id="txt" runat="server" />
<br />
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="button1_Click" />
</div>
</form>
</body>
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True;");
try
{
SqlCommand cmd = new SqlCommand("INSERT INTO customers(firstName,lastName,address,city) VALUES ('wee','weeee','dfddd', 'weee')", conn);
conn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Connection Succeful");
}
catch (SqlException ex)
{
MessageBox.Show("There is an Error" + ex);
}
finally
{
conn.Close();
MessageBox.Show("Connection Closed");
}
}
Accept as answer and vote if help to you.