| | |
FileUpload automatically upload after set filepath
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 55
Reputation:
Solved Threads: 1
Hi,
I have a gridview that has a fileupload (fupRespuesta) control in a itemtemplate field, I need to enable automatic upload after file is selected.
Then I added a imageButton (imgRespuesta) in the template field and added its event with addhandler...
Well my problem is that when I uncomment the red line, the event of the image button don't fire (I can't understand why)
I need it work, or some other idea to do it.
Heres my code:
I have a gridview that has a fileupload (fupRespuesta) control in a itemtemplate field, I need to enable automatic upload after file is selected.
Then I added a imageButton (imgRespuesta) in the template field and added its event with addhandler...
Well my problem is that when I uncomment the red line, the event of the image button don't fire (I can't understand why)
I need it work, or some other idea to do it.
Heres my code:
Private Sub gv_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPropuestasDiagnosticoListar.RowCreated
Dim imgRespuesta As New ImageButton
Dim fupRespuesta As New FileUpload
imgRespuesta = e.Row.FindControl("imgProDiagUploadRespuesta")
fupRespuesta = e.Row.FindControl("fupvcProDiaRutaRespuesta")
If Not imgRespuesta Is Nothing And Not fupRespuesta Is Nothing Then
AddHandler imgRespuesta.Click, AddressOf img_Click
'imgRespuesta.Attributes.Add("Style", "Display:none")
'fupRespuesta.Attributes.Add("onchange", "return document.getElementById('" + imgRespuesta.ClientID + "').click();")
End If
End Sub
Private Sub img_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim fup As FileUpload
Dim img As ImageButton
fup = CType(sender.Parent.Parent, GridViewRow).FindControl("fupvcProDiaRutaPropuesta")
img = CType(sender.Parent.Parent, GridViewRow).FindControl("imgProDiagUploadPropuesta")
If fup.HasFile = True Then
img.Attributes.Remove("Style")
Dim fullpath = IO.Path.GetFullPath(fup.FileName)
Dim name = IO.Path.GetFileName(fullpath)
fup.SaveAs(Server.MapPath("~") + "\Documentos\" & name.ToString)
End If
End Sub•
•
Join Date: Jun 2009
Posts: 432
Reputation:
Solved Threads: 82
Write the following code in RowDataBound event of the GridView control. This code is to attach onChange event of the file upload control to the click event of image button control.
Write this code in RowCreated event of the GridView. This code is to set style for image button and add handler to it.
I have tested this way in C#. It is working for me. I can able to reach img_Click event if a file is browsed and selected.
imgRespuesta = e.Row.FindControl("imgProDiagUploadRespuesta")fupRespuesta = e.Row.FindControl("fupvcProDiaRutaRespuesta")
fupRespuesta.Attributes.Add("onchange", "return document.getElementById('" + imgRespuesta.ClientID + "').click();")Write this code in RowCreated event of the GridView. This code is to set style for image button and add handler to it.
imgRespuesta = e.Row.FindControl("imgProDiagUploadRespuesta")
imgRespuesta.Attributes.Add("Style", "Display:none")
AddHandler imgRespuesta.Click, AddressOf img_ClickI have tested this way in C#. It is working for me. I can able to reach img_Click event if a file is browsed and selected.
•
•
Join Date: Aug 2007
Posts: 55
Reputation:
Solved Threads: 1
I tried it, and it reaches the event, as you said, but the problem now is that the HasFile property of the FileUpload control is false when after I select the file... And I don't know why...
I hope you can help me with this...
I hope you can help me with this...
Private Sub imgEnvio_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim fup As FileUpload
Dim img As ImageButton
fup = CType(sender.Parent.Parent, GridViewRow).FindControl("fupvcProDiaRutaPropuesta")
img = CType(sender.Parent.Parent, GridViewRow).FindControl("imgProDiagUploadPropuesta")
If fup.HasFile Then <-- this is not true after I select the file
img.Attributes.Remove("Style")
Dim fullpath = IO.Path.GetFullPath(fup.FileName)
Dim name = IO.Path.GetFileName(fullpath)
fup.SaveAs(Server.MapPath("~") + "\Documentos\" & name.ToString)
End If
End Sub•
•
•
•
Write the following code in RowDataBound event of the GridView control. This code is to attach onChange event of the file upload control to the click event of image button control.
imgRespuesta = e.Row.FindControl("imgProDiagUploadRespuesta")fupRespuesta = e.Row.FindControl("fupvcProDiaRutaRespuesta") fupRespuesta.Attributes.Add("onchange", "return document.getElementById('" + imgRespuesta.ClientID + "').click();")
Write this code in RowCreated event of the GridView. This code is to set style for image button and add handler to it.
imgRespuesta = e.Row.FindControl("imgProDiagUploadRespuesta") imgRespuesta.Attributes.Add("Style", "Display:none") AddHandler imgRespuesta.Click, AddressOf img_Click
I have tested this way in C#. It is working for me. I can able to reach img_Click event if a file is browsed and selected.
![]() |
Similar Threads
- Please help me in upload code (JSP)
- Cant upload mp3's with this script? (PHP)
- Would the file size affect the upload? (PHP)
- How to make flash slideshow for your website and blog? (Windows NT / 2000 / XP)
- How to make flash slideshow? (HTML and CSS)
- How to make flash slideshow? (Windows NT / 2000 / XP)
- how do I upload a file into the database from dreamweaver? (ASP)
- Save Target as... (JavaScript / DHTML / AJAX)
- Windows 2000 Adv Server and "Printing Subsystem" (Windows NT / 2000 / XP)
Other Threads in the ASP.NET Forum
- Previous Thread: login code with roles
- Next Thread: how to convert flash menu into static menu
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





