I have this code that helps to clear the textbox after submitting data, but is generating error, i wanted to clear all textbox after submit
error
Error CS0106 The modifier 'public' is not valid for this item
protected void btnsave_Click(object sender, EventArgs e)
{
int inserted = 0;
if (txtqty.Text.Length > 0 && ddprice.Text.Length > 0)
{
float qty2 = !string.IsNullOrEmpty(txtqty.Text.Trim()) ? float.Parse(txtqty.Text.Trim()) : float.Parse("0"); ;
float price = !string.IsNullOrEmpty(ddprice.SelectedItem.Text.Trim()) ? float.Parse(ddprice.SelectedItem.Text.Trim()) : float.Parse("0"); ;
float totalprice = qty2 * price;
float finalprice = totalprice;
if (txtqty.Text.Length > 0 && ddprice.Text.Length > 0)
{
float disc = !string.IsNullOrEmpty(ddiscount.SelectedItem.Text.Trim()) ? float.Parse(ddiscount.SelectedItem.Text.Trim()) : float.Parse("0"); ;
float sum = totalprice - disc;
float gtotal = sum;
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = str;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
//Change the query like below
//Make sure the column name matches the with the name provided in code as per your table
cmd.CommandText = "INSERT INTO DAILYSales (AttendedBy,Staff_Assigned,Customer_Phone,Job_Category,Quantity,Price,Material,Width,Height,Unit,Discount,After_Discount,Sum) VALUES(@AttendedBy,@Staff_Assigned,@Customer_Phone,@Job_Category,@Quantity,@Price,@Material,@Width,@Height,@Unit,@Discount,@After_Discount,@Sum)";
cmd.Parameters.AddWithValue("@AttendedBy", HttpContext.Current.User.Identity.Name);
cmd.Parameters.AddWithValue("@Job_Category", ddlproductcategory.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Staff_Assigned", ddlstaff.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Customer_Phone", ddlphone.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Quantity", txtqty.Text);
cmd.Parameters.AddWithValue("@Price", ddprice.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Material", ddlmaterial.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Width", txtwidth.Text);
cmd.Parameters.AddWithValue("@Height", txtheight.Text);
cmd.Parameters.AddWithValue("@Discount", ddiscount.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Unit", txtunit.Text);
cmd.Parameters.AddWithValue("@Sum", totalprice);
cmd.Parameters.AddWithValue("@After_Discount", sum);
con.Open();
inserted = cmd.ExecuteNonQuery();
con.Close();
BindGridreport();
string message = string.Empty;
{
// lblMessage2.Visible = true;
/// lblMessage2.Text = "Data Submitted Successfully";
}
ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "alert", "<script>alert('Data Submitted Successfully ... !!')</script>", false);
// lblMessage2.Text = "Inserted Quantity Is Higher than stock " + GetQuantity().ToString();
}
}
}
CleartextBoxes(this);
}
public void CleartextBoxes(Control parent)
{
foreach (Control c in parent.Controls)
{
if ((c.GetType() == typeof(TextBox)))
{
((TextBox)(c)).Text = "";
}
if (c.HasControls())
{
CleartextBoxes(c);
}
}
}
// this.BindGrid();
}