473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 4196

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mark | last post by:
I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this: if (isset($_POST)) { if ($_POST ==...
1
by: Lew | last post by:
Hi all, I'm trying to create a page that has a user-selectable page auto-refresh option (IE 5.5). Essentially, it's a page that contains a checkbox, when the user checks the checkbox, I'd like...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
8
by: Nathan Sokalski | last post by:
I have a form that submits data to a database. If I click the browser's refresh button after submitting the form once, the form is submitted a second time. How can I avoid this problem? Thanks. --...
9
by: Mr Newbie | last post by:
Before someone flames me, I know this is the VB.NET groups, nonetheless, the asp.net guys seems to have almost disapeared from the aspnet groups so I thought I would ask this here. I have a...
2
by: Mr Newbie | last post by:
Before someone flames me, I know this is the VB.NET groups, nonetheless, the asp.net guys seems to have almost disapeared from the aspnet groups so I thought I would ask this here. I have a...
1
by: fugaki | last post by:
Hi everyone I'm learning asp, and i downloaded this script to teach me how to post form data from a webpage to an access database. I put it on the server so i could make sure that it worked, and...
4
by: hemricc2 | last post by:
I have the following simple page. I need to select the BARCODE text field everytime the page refreshes. I know this is pretty basic, but I'm just starting with Javascript. Thanks for the help. ...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.