In your code you didn't use
IsPostBack
property
so try below code:-
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS; AttachDbFileName=|DataDirectory|\\Database.mdf; user instance=true; trusted_connection=yes");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM signup WHERE id='" + (string)Session["User"] + "'", con);
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
TextBox1.Text = rd.GetString(0).ToString();
TextBox2.Text = rd.GetString(1).ToString();
TextBox3.Text = rd.GetString(2).ToString();
TextBox4.Text = rd.GetString(5).ToString();
TextBox5.Text = rd.GetString(6).ToString();
DropDownList1.SelectedValue = rd.GetString(7).ToString();
TextBox6.Text = rd.GetString(8).ToString();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS; AttachDbFileName=|DataDirectory|\\Database.mdf; user instance=true; trusted_connection=yes");
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE signup SET fn = '" + this.TextBox1.Text + "', ln = '" + this.TextBox2.Text + "', emailid= '" + this.TextBox4.Text + "', address = '" + this.TextBox5.Text + "', scquestion = '" + this.DropDownList1.SelectedValue + "', answer = '" + this.TextBox6.Text + "' WHERE id = '" + (string)Session["User"] + "' ", con);
SqlDataReader rd = cmd.ExecuteReader();
con.Close();
Label3.Text = "Update successfully";
}