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