I know this is a very basic question, and I am sure there are answers for it already on the forum. I don't even know how to properly phrase it to search, so here goes. I have button that has the OnClick property set to "InsertCard" and the corresponding code of:
protected void InsertCard (object source, EventArgs e) {
SqlDataSource1.Insert();
}
This works exactly as intended. I also want to clear all the text boxes on the page after the button is clicked. If I change the OnClick property to "ClearText" and have the corresponding code of:
protected void ClearText_Click(object sender, EventArgs e)
{
ClearControls();
}
private void ClearControls()
{
foreach (Control c in Page.Controls)
{
foreach (Control ctrl in c.Controls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Text = string.Empty;
}
}
}
}
This works perfectly too.
My question is how do I combine both actions into one, so that when I click the button, I insert the data to the database AND then clear all fields? I have tried many variations but always get some type of compiler error.
Also, is there some type of guide to assist me in using the right syntax for asking questions/searching for answers?