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>
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>