Click to See Complete Forum and Search --> : Sub Executes 2 Times????


lmf232s
03-21-2006, 10:42 PM
I have a page w/ an <asp:FileUpload> and an image button.

Click on the button and it calls the button_Click sub, uploads the file, calls another sub w/ executes a sp and writes the info to the database.

It works but for what ever reason its actually running the button_click sub twice, so i end up w/ 2 data base records that are exaclty the same.

No Clue?? (Its calling Sub General.UploadProbingNews twice)

Here is the code


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles UploadProbingNews.Click
If Me.PhotoFile.HasFile Then
'Upload File
Me.PhotoFile.SaveAs(Server.MapPath("../SharedFiles/") & Me.PhotoFile.FileName)

'Call Sub
General.UploadProbingNews(Me.PhotoFile.FileName, Me.PhotoCaption.Text)

'Display Results
Label1.Text = "Received " & Me.PhotoFile.FileName & " Content Type " & Me.PhotoFile.PostedFile.ContentType & " Length " & Me.PhotoFile.PostedFile.ContentLength
Else
Label1.Text = "No uploaded file"
End If
End Sub



Public Shared Sub UploadProbingNews(ByVal sFileName As String, ByVal sCaption As String)
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Personal").ConnectionString)
Using command As New SqlCommand("AddProbingNews", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New SqlParameter("@FilePath", sFileName))
command.Parameters.Add(New SqlParameter("@Caption", sCaption))
command.Parameters.Add(New SqlParameter("@DateCreated", Now()))
connection.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub



Photo<br />
<asp:FileUpload ID="PhotoFile" Runat="server" FileBytes='<%# Bind("BytesOriginal") %>' Width="250px" /><br />
Caption<br />
<asp:TextBox ID="PhotoCaption" Runat="server" Width="326" Text='<%# Bind("Caption") %>' CssClass="textfield" /><br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<p style="text-align:right;">
<asp:ImageButton ID="UploadProbingNews" Runat="server" onclick="Button1_Click" skinid="add" Height="29px" Width="48px"/>
</p>

chrisranjana
03-28-2006, 07:40 AM
Have you tried changing

<asp:ImageButton ID="UploadProbingNews" Runat="server" onclick="Button1_Click" skinid="add" Height="29px" Width="48px"/>


to

say

<asp:ImageButton ID="UploadProbingNews1" Runat="server" onclick="Button1_Click" skinid="add" Height="29px" Width="48px"/>

or something ?

lmf232s
03-28-2006, 03:17 PM
I forget what i did to fix this the other night but im pretty sure it was a naming that as you have mentioned. I think the sub and the id of the button were the same name and somehow the Button1_Click was being executed twice.

Gosh im not at home right now so i cant remeber what i did. Ill post back if i can remember but i really think it was a naming convention problem.

Thanks.