By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,357 Members | 982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,357 IT Pros & Developers. It's quick & easy.

page refresh resubmits input form data!

P: n/a
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?

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.