1

I'm new here. I have a question.

Everyting is OK, but when I click on F5, it refresh the page and run the code another time. This means a new record is added to the data base on each F5.

This is my code, do you have any advices?

Imports System.Data.OleDb
Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim myConn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim sqlstring, Fname, Lname, FATHname, Region As String

        Fname = TextBox1.Text
        Lname = TextBox2.Text
        FATHname = TextBox3.Text
        Region = TextBox4.Text

        myConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\pcuser10.comm\Documents\vwd.data.accdb")

        myConn.Open()

        sqlstring = " INSERT INTO Table1 (FNAME, LNAME, FATHNAME, REGION) VALUES ('" + Fname + "','" + Lname + "','" + FATHname + "','" + Region + "')"

        cmd = New OleDbCommand(sqlstring, myConn)
        cmd.ExecuteNonQuery()

        myConn.Close()
    End Sub
End Class
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
user1000744
  • 123
  • 1
  • 4
  • 12
  • Since you are new, please explore existing questions. This one is already anwwered e.g. http://stackoverflow.com/q/1558790/532498 or even better look here http://stackoverflow.com/questions/1135404/btnadd-click-fires-when-i-press-f5 – Pleun Nov 11 '11 at 08:05
  • thank u for the help , i used Response.Redirect(Request.RawUrl, true) , it refresh the page and clear fields , that solved my question , thank u again – user1000744 Nov 11 '11 at 09:00

2 Answers2

0

Theres a good answer from MainMa in this forum for a related question.

page refresh is firing the event again

theres nothing more i can add, so check out :)

Community
  • 1
  • 1
SwissGuy
  • 565
  • 1
  • 6
  • 18
0

The easiest way? Wrap all your controls into an UpdatePanel.

<body>
   <asp:UpdatePanel ID="upBody" runat="server">
      <ContentTemplate>

----------All your HTML controls here ----------

      </ContentTemplate>
   </asp:UpdatePanel>
</body>

well, I don't recommend this one but is better than your current situation now.

Alvin
  • 985
  • 5
  • 13
  • thank u for the help , i used Response.Redirect(Request.RawUrl, true) , it refresh the page and clear fields , that solved my question , thank u again – user1000744 Nov 11 '11 at 09:18