I have an issue with my default value for the textboxes on the form. When the page loads the textboxes all have zeros in them. When a user enters the data and clicks submit the data is saved and the page reloads but the textboxes are empty. What did I do wrong? I set the textbox property Text to "0".
<asp:TextBox ID="TextBoxTNUGSC" runat="server" Width="180px" Text= "0"></asp:TextBox>
Code Behind for the Submit Button:
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Table22 (INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR, DATE, TIME) values (@INST_ID, @UNITID, @ASTUDENTS, @ACOMPLETED, @ATRANSFERS, @BSTUDENTS, @BCOMPLETED, @BTRANSFERS, @YEAR, @DATE, @TIME)Insert into Table23 (INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR, DATE, TIME) values (@INST_ID, @UNITID, @ASTUDENTS, @ACOMPLETED, @ATRANSFERS, @BSTUDENTS, @BCOMPLETED, @BTRANSFERS, @YEAR, @DATE, @TIME)", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@ASTUDENTS", TextBoxTNUGSC.Text);
cmd.Parameters.AddWithValue("@ACOMPLETED", TextBoxTNUGSCD.Text);
cmd.Parameters.AddWithValue("@ATRANSFERS", TextBoxTTOUG.Text);
cmd.Parameters.AddWithValue("@BSTUDENTS", TextBoxTNGSC.Text);
cmd.Parameters.AddWithValue("@BCOMPLETED", TextBoxTNGSCD.Text);
cmd.Parameters.AddWithValue("@BTRANSFERS", TextBoxTTOG.Text);
cmd.Parameters.AddWithValue("@YEAR", TextBoxYEAR.Text);
cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
cmd.Parameters.AddWithValue("@UNITID", TextBoxUNITID.Text);
cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
cmd.Parameters.AddWithValue("@TIME", lblTime.Text);
cmd.ExecuteNonQuery();
con.Close();
if (Page.IsValid)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Cohort');", true);
}
else
{
Response.Redirect("Gradrate.aspx");
}
TextBoxUNITID.Text = string.Empty;
TextBoxTNUGSC.Text = string.Empty;
TextBoxTNUGSCD.Text = string.Empty;
TextBoxTTOUG.Text = string.Empty;
TextBoxTNGSC.Text = string.Empty;
TextBoxTNGSCD.Text = string.Empty;
TextBoxTTOG.Text = string.Empty;
}