469,658 Members | 1,872 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,658 developers. It's quick & easy.

page refresh resubmits input form data!

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
0 3998

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Mark | last post: by
1 post views Thread by Lew | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
9 posts views Thread by Mr Newbie | last post: by
2 posts views Thread by Mr Newbie | last post: by
1 post views Thread by fugaki | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.