Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP/VB.NET Sub Routine running twice

Posted on 2009-04-01
6
Medium Priority
?
581 Views
Last Modified: 2012-05-06
Can anyone tell me why my sub routine would all of a sudden start running 2 times?

Protected Sub Submitbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submitbtn.Click
        Dim con As New System.Data.OleDb.OleDbConnection
        Dim myPath As String
        Dim Today
        Dim TodayDate
 
        Today = Now()
        TodayDate = FormatDateTime(Today, 2)
 
        myPath = Server.MapPath("App_Data/Visions_DB.mdb")
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
 
        Dim insCmd As New System.Data.OleDb.OleDbCommand
 
        insCmd.CommandText = "insert into Data (MDY,Employee,Department,Vision_Type,Critical_Success,Present_Method,Proposed_Method,Ats_Number,Drawing_Number,MO_Number,Status,Add_Emp1,Add_Emp2,Add_Emp3,Add_Emp4,Add_Emp5,Add_Emp6,Add_Emp7,Add_Emp8) values('" & _
        TodayDate & "','" & Replace(txtName.SelectedValue, "'", "''") & "','" & Replace(txtdept.Text, "'", "''") & "','" & ddtype.SelectedValue & "','" & ddfactor.SelectedValue & "','" & _
        Replace(txtapres.Text, "'", "''") & "','" & Replace(txtapros.Text, "'", "''") & "','" & Replace(txtats.Text, "'", "''") & "', '" & Replace(txtdrawing.Text, "'", "''") & "','" & _
        Replace(txtmo.Text, "'", "''") & "','" & Replace(txtstatus.Text, "'", "''") & "','" & Replace(emp1.SelectedValue, "'", "''") & "','" & Replace(emp2.SelectedValue, "'", "''") & "','" & Replace(emp3.SelectedValue, "'", "''") & "','" _
        & Replace(emp4.SelectedValue, "'", "''") & "','" & Replace(emp5.SelectedValue, "'", "''") & "','" & Replace(emp6.SelectedValue, "'", "''") & "','" & Replace(emp7.SelectedValue, "'", "''") & "','" & Replace(emp8.SelectedValue, "'", "''") & "')"
 
        insCmd.Connection = con
 
        Dim idCmd As New System.Data.OleDb.OleDbCommand
        'Captures Vision Number
        idCmd.CommandText = "select @@IDENTITY"
 
        idCmd.Connection = con
        con.Open()
        insCmd.ExecuteNonQuery()
        Dim newid As Integer = idCmd.ExecuteScalar()
        con.Close()
 
        Response.Write("<div id=""hideprint"">")
        Response.Write("<h1><font color = Red>Your Vision form has been successfully submitted!!</font></h1>")
        Response.Write("<h2><font color = Red>Your Vision number is " & (newid.ToString) & " </font></h2>")
        Response.Write("<h2><font color = Red>Please print this page for your records.</font></h2>")
        Response.Write("</div>")
 
        'sets Vision # value after clicking submit
        lblvisnum.Text = newid.ToString
 
        'Makes print and close button visible after clicking submit
        btnprint.Visible = True
        btnclose.Visible = True
    End Sub

Open in new window

0
Comment
Question by:ITHelper80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24039365
The event handler's running twice? Have you manually hooked the event handler as well as using the designer?

ie. does your code contain this:
AddHandler Submitbtn.Click, AddressOf Submitbtn_Click
0
 
LVL 8

Expert Comment

by:JRockFL
ID: 24039386
You can add a break point at Protected Sub to verify that it is actually be hit twice.
Then you can step through the code and see why. You can also check the call stack to what called that method.

Also,
idCmd.CommandText = "select @@IDENTITY"
@@IDENTITY is a SQL Server variable.
In access, you would need to use MAX() or TOP() ?
0
 
LVL 6

Author Comment

by:ITHelper80
ID: 24039391
No it doesnt...Ive stepped through the code and once it hits the end sub command it starts over and I dont see anything that is causing it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Accepted Solution

by:
JRockFL earned 2000 total points
ID: 24039454
Another option would be to copy all that code to notepage. Delete the button.
Add a new button, double click on it and paste back the code.
0
 
LVL 6

Author Comment

by:ITHelper80
ID: 24039516
Thanks JRockFL that did it.

I wonder why it did that....very frustrating.
0
 
LVL 8

Expert Comment

by:JRockFL
ID: 24039550
No problem. I had to do that when converted a 1.1 web site to 2.0
None of the button click events were hooked up.

I found that recreating it solved the problem.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question