Ask a Question related to ASP.NET General, Design and Development.
-
lucas #1
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("<", "<");
_name = _name.Replace(">", ">");
string _email = txtbEmail.Text.Replace("<", "<");
_email = _email.Replace(">", ">");
string _message = txtbMessage.Text.Replace("<", "<");
_message = _message.Replace(">", ">");
_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?
lucas Guest
-
Pulling up another page based on input in a form
I have a simple website with a form & one field that is for a drawing number. I want the user to input the drawing number & pull the drawing up... -
Prevent data insert on page refresh
After a form is submited and inserted to the database, if the user hits the refresh button the data is again inserted to the database (there is a... -
Insert data into a form based on user input
You have a list menu field call company invoice number and 2 other fields called customer name and cust invoice. Is there a way to have the user... -
Page does not refresh after submitting form
Natty, I apologize for not getting back to you on this one. I had to redirect my focus. I'm now running into the same issue again, and although... -
how can i make my form refresh its data
am asking how can i make the form refresh its data when i choose something ( any data ) from a combo box as example ( when i choose data frm a combo...



Reply With Quote

