Esta pagina segun le pasas unos parametros crea x updatepanel, que creo asi:
Código:
Este codigo lo uso en dos proyectos diferentes, y tengo varios problemas:Public Shared Function generateFileConfirmado(ByVal field As Field) As System.Web.UI.Control Dim ctr As System.Web.UI.Control = New System.Web.UI.Control() ctr.ID = "field_ctr_" & field.id Dim UpdatePanel1 As UpdatePanel = New UpdatePanel() UpdatePanel1.ID = "field_UpdatePanel_" & field.id Dim CheckBox1 As CheckBox = New CheckBox() CheckBox1.ID = "field_CheckBox_" & field.id CheckBox1.AutoPostBack = True 'CheckBox1.Sorted = True CheckBox1.CssClass = "CheckBoxField" AddHandler CheckBox1.CheckedChanged, AddressOf LibraryTramitesCiudadano.CheckBox1_CheckedChanged Dim FileUpload1 As FileUpload = New FileUpload() FileUpload1.ID = "field_" & field.id FileUpload1.CssClass = "FileUploadField" Dim UpLoadFileConfirmado As LinkButton = New LinkButton() UpLoadFileConfirmado.ID = "field_UpLoad_" & field.id UpLoadFileConfirmado.Text = "Subir" AddHandler UpLoadFileConfirmado.Click, AddressOf LibraryTramitesCiudadano.UpLoadFileConfirmado_click Dim DownloadFileConfirmado As HyperLink = New HyperLink() DownloadFileConfirmado.ID = "field_Download_" & field.id DownloadFileConfirmado.Text = "Descargar" DownloadFileConfirmado.Target = "_ablank" DownloadFileConfirmado.CssClass = "HyperLinkField" Dim Espacio As Label = New Label() Espacio.ID = "field_Espacio_" & field.id Espacio.Text = "          " Dim DeleteFileConfirmado As LinkButton = New LinkButton() DeleteFileConfirmado.ID = "field_Delete_" & field.id DeleteFileConfirmado.Text = "Eliminar" AddHandler DeleteFileConfirmado.Click, AddressOf LibraryTramitesCiudadano.DeleteFileConfirmado_click If field.defaultValue <> "" And field.defaultValue <> "[UNDEFINED]" And field.defaultValue <> "Sin Documento" And field.defaultValue <> "False" Then 'tiene algo CheckBox1.Checked = True CheckBox1.Enabled = False FileUpload1.Visible = False UpLoadFileConfirmado.Visible = False DownloadFileConfirmado.NavigateUrl = "~/viewdoc.aspx?dID=" & field.defaultValue Else 'no tiene nada FileUpload1.Enabled = False UpLoadFileConfirmado.Visible = False 'UpLoadFileConfirmado.Enabled = False DownloadFileConfirmado.Visible = False Espacio.Visible = False DeleteFileConfirmado.Visible = False End If Dim AsyncPostBackTrigger1 As AsyncPostBackTrigger = New AsyncPostBackTrigger() AsyncPostBackTrigger1.ControlID = "field_CheckBox_" & field.id AsyncPostBackTrigger1.EventName = "CheckedChanged" Dim PostBackTrigger2 As PostBackTrigger = New PostBackTrigger() PostBackTrigger2.ControlID = "field_UpLoad_" & field.id PostBackTrigger2.EventName = "Click" Dim AsyncPostBackTrigger3 As AsyncPostBackTrigger = New AsyncPostBackTrigger() AsyncPostBackTrigger3.ControlID = "field_Delete_" & field.id AsyncPostBackTrigger3.EventName = "Click" UpdatePanel1.ContentTemplateContainer.Controls.Add(CheckBox1) UpdatePanel1.ContentTemplateContainer.Controls.Add(FileUpload1) UpdatePanel1.ContentTemplateContainer.Controls.Add(UpLoadFileConfirmado) UpdatePanel1.ContentTemplateContainer.Controls.Add(DownloadFileConfirmado) UpdatePanel1.ContentTemplateContainer.Controls.Add(Espacio) UpdatePanel1.ContentTemplateContainer.Controls.Add(DeleteFileConfirmado) UpdatePanel1.Triggers.Add(AsyncPostBackTrigger1) UpdatePanel1.Triggers.Add(PostBackTrigger2) UpdatePanel1.Triggers.Add(AsyncPostBackTrigger3) ctr.Controls.Add(UpdatePanel1) Return ctr End Function Protected Shared Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim chk As CheckBox = sender Dim fu As FileUpload = sender.Parent.FindControl("field_" & sender.ID.Replace("field_CheckBox_", "")) Dim bo As LinkButton = sender.Parent.FindControl("field_UpLoad_" & sender.ID.Replace("field_CheckBox_", "")) If chk.Checked = True Then fu.Enabled = True bo.Enabled = True Else fu.Enabled = False bo.Enabled = False End If End Sub Protected Shared Sub UpLoadFileConfirmado_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim bo As LinkButton = sender Dim fu As FileUpload = sender.Parent.FindControl("field_" & sender.ID.Replace("field_UpLoad_", "")) If fu.HasFile = True Then Dim documento As Valor = New Valor() documento.idField = sender.ID.Replace("field_UpLoad_", "") Dim Cadena As String Cadena = sender.page.ClientQueryString Cadena = Cadena.Replace("dId=", "") Cadena = Cadena.Replace("&p=Consultoria", "") Dim did As Integer did = CInt(Cadena) Dim expe As Expediente = New Expediente() expe = Expediente.getExpedienteWithDid(did) documento.idExpediente = expe.id documento.ctr = fu documento.update() Dim fie As Field = New Field() fie = Field.getField(documento.idField) documento = Valor.getValor(expe, fie) 'Cambiamos el control Dim chk As CheckBox = sender.Parent.FindControl("field_CheckBox_" & sender.ID.Replace("field_UpLoad_", "")) Dim hl As HyperLink = sender.Parent.FindControl("field_Download_" & sender.ID.Replace("field_UpLoad_", "")) Dim de As LinkButton = sender.Parent.FindControl("field_Delete_" & sender.ID.Replace("field_UpLoad_", "")) Dim es As Label = sender.Parent.FindControl("field_Espacio_" & sender.ID.Replace("field_UpLoad_", "")) chk.Enabled = False fu.Visible = False bo.Visible = False chk.Checked = True hl.Visible = True hl.NavigateUrl = "~/viewdoc.aspx?dID=" & documento.valor es.Visible = True de.Visible = True End If End Sub Protected Shared Sub DeleteFileConfirmado_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim de As LinkButton = sender Dim hl As HyperLink = sender.Parent.FindControl("field_Download_" & sender.ID.Replace("field_Delete_", "")) Dim documento As Valor = New Valor() Dim Cadena As String Cadena = sender.page.ClientQueryString Cadena = Cadena.Replace("dId=", "") Cadena = Cadena.Replace("&p=Consultoria", "") Dim did As Integer did = CInt(Cadena) Dim expe As Expediente = New Expediente() expe = Expediente.getExpedienteWithDid(did) documento.idExpediente = expe.id documento.idField = sender.ID.Replace("field_Delete_", "") documento.delete() 'Cambiamos el control Dim chk As CheckBox = sender.Parent.FindControl("field_CheckBox_" & sender.ID.Replace("field_Delete_", "")) Dim fu As FileUpload = sender.Parent.FindControl("field_" & sender.ID.Replace("field_Delete_", "")) Dim bo As LinkButton = sender.Parent.FindControl("field_UpLoad_" & sender.ID.Replace("field_Delete_", "")) Dim es As Label = sender.Parent.FindControl("field_Espacio_" & sender.ID.Replace("field_Delete_", "")) chk.Enabled = True chk.Checked = False fu.Visible = True fu.Enabled = False bo.Visible = True hl.Visible = False es.Visible = False de.Visible = False End Sub
Proyecto 1:
-Cuando hago click en el check me activa y desactiva el FileUpload, pero si en alguno hay algo elejido lo borra al recargar la pagina (cosa que no quiero que haga)
-Cuando hago click en el boton subir o en eliminar, sube o elimina correctamente, y recarga el panelupload pero me recarga la pagina
Proyecto 2:
-Al tener activado en el check el AutoPostBack me carga la pagina y me da fallo al recargar, pero si lo pongo a False no me hace nada, no quiero que recargue la pagina pero quiero que valla!!!
(Este proyecto tiene el boton subir invisible y no tiene opcion de poder descargar o eliminar)
Cualquier duda avisar, ya se que me explico mal :P
Gracias por la ayuda que me podais dar