I have a couple upload controls on my page that are being shown by the ajax ModalPopUpExtender, but they don't work at the moment. Can someone help me figure out what is wrong so that they can start getting information into my database?
By the way, I don't know what the hidden field is for or 开发者_JAVA百科is doing, so if someone understands that, please explain it to me. I didn't write this, I'm just trying to fix it.
<!-- Add a Document -->
<li>
<asp:LinkButton ID="DocumentButton" runat="server">Document</asp:LinkButton>
<asp:Panel ID="DocumentPanel" runat="server" CssClass="modalPopup" Style="display:none">
<asp:FileUpload ID="DocumentUpload" runat="server" />
<asp:Button ID="SubmitDocument" runat="server" Text="Upload" onclick="SubmitDocument_Click" /><asp:Button ID="CancelDocument" runat="server" Text="Cancel" /><asp:HiddenField ID="filename" runat="server" />
</asp:Panel>
<asp:ModalPopupExtender ID="DocumentModal" runat="server" DropShadow="True"
DynamicServicePath="" Enabled="True" OkControlID="SubmitDocument" PopupControlID="DocumentPanel" TargetControlID="DocumentButton"></asp:ModalPopupExtender>
</li>
Protected Sub SubmitDocument_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitDocument.Click
'Builds the full absolute URL to be inserted into the database.
Dim hostURL As String = Request.Url.Scheme & "://" & Request.Url.Host & ":" & Request.Url.Port & Request.ApplicationPath
Dim sqlFileHREF As String = "INSERT INTO Marketing (ProductID, MarketingTypeID, MarketingTitle, MarketingData) VALUES (" & ProductID.Value & " , 4 , '" & LinkTitle.Text & "', '" & hostURL & "uploads/" & ProductID.Value & "/" & filename.Value & "')"
'Create SQL Connection
Dim SqlConnection As New SqlConnection("Server=off-db1;uid=productsDB_admin;pwd=*****;database=Products")
SqlConnection.Open()
Dim sqlCommand As New SqlCommand(sqlFileHREF, SqlConnection)
sqlCommand.ExecuteNonQuery()
SqlConnection.Close()
Response.Redirect(Request.RawUrl)
End Sub
setting OkControlID="SubmitDocument"
in the ModalPopupExtender prevent the Click
event of the SubmitDocument
Button to be raised on the server-side.
first thing to try is to remove it and add a DocumentModal.hide()
in the SubmitDocument_Click
Sub.
Update :
Then you could add a watch to sqlFileHREF
to find what is causing the Incorrect syntax near ','.
I suspect that you have a quote or others specials character in it. You could do somthing like sqlFileHREF.Replace("'", "''")
to double your quotes.
Note : Executing SQL code like this make you vulnerable to SQL Injection!
Note 2 : It would be wise to remove the password from the connection string and replace it with stars in yours future posts (pwd=********
) (you should edit this one)
Update 2 :
Use DocumentUpload.FileName
instead of filename.Value
, it look like the filename HiddenField was there for some unimplemented feature or testing purpose.
精彩评论