page refresh resubmits input form data!

L

lucas

Hi,
I have a simple input form that i use to add records to a sql server
database. Bellow that is a datagrid that has one template column that I
use to dispaly the 3 fields with some html formating. the datagrid also
has paging.

I'm doing a ASP.NET guestbook. I know some things could be improved like
adding some error handling and caching the dataset instead of querying
the database on every page load....but I'm still working on the basics.

When I click my submit button, the data is added to the database but the
datagrid dosn't refresh. If I refresh the page, the data is added to the
database everytime I do so, and the data (from the preceding submission)
becomes visible in the datagrid! If I submit some new data a second time
the one I submited in the preceding post becomes visible in the
datagrid. I tried adding the data to the dataset and then calling the
update command on the dataset instead of the sqlInsertCommand but I get
the same result.


Theese are my page load and button click events:


private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}

private void btnSubmit_Click(object sender, System.EventArgs e)
{
//start data validation
string _name = txtbName.Text.Replace("<", "&lt;");
_name = _name.Replace(">", "&gt;");
string _email = txtbEmail.Text.Replace("<", "&lt;");
_email = _email.Replace(">", "&gt;");
string _message = txtbMessage.Text.Replace("<", "&lt;");
_message = _message.Replace(">", "&gt;");
_message = _message.Replace("\r\n", "<br>");
//end data validation

//add the data to the database
sqlInsertCommand1.Parameters["@name"].Value = _name;
sqlInsertCommand1.Parameters["@email"].Value = _email;
sqlInsertCommand1.Parameters["@message"].Value = _message;
sqlConnection1.Open();
sqlInsertCommand1.ExecuteNonQuery();
sqlConnection1.Close();

//clear the text boxes on the input form
txtbName.Text = "";
txtbEmail.Text = "";
txtbMessage.Text = "";

//update the dataset and rebind the datagrid
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}

I nead for the datagrid to be refreshed when the submit button is
clicked and a page refresh shouldn't resubmit the data.
Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top