CassidyHunt
IS-IT--Management
I am creating fileupload controls and a button control using the below code. Everything works great for adding the controls to the form. However when I click the button all the controls disappear and nothing is available to check for upload.
I am guessing there is a command to keep the controls available during the round trip but I do not know what that would be.
Thanks
Cassidy
Code:
<%@ Page Language="VB" MasterPageFile="~/Admin/MasterPage.master" Title="The Hunt Family -- Picture Manager" %>
<script runat="server">
Protected Sub bUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim uTable As Table = up.FindControl("uTable")
For Each o As Object In uTable.Controls
If TypeOf (o) Is System.Web.UI.HtmlControls.HtmlTableRow Then
Dim tr As System.Web.UI.HtmlControls.HtmlTableRow = o
For Each a As Object In tr.Controls
If TypeOf (a) Is System.Web.UI.HtmlControls.HtmlTableCell Then
Dim tc As System.Web.UI.HtmlControls.HtmlTableCell = a
For Each b As Object In tc.Controls
If TypeOf (b) Is System.Web.UI.WebControls.FileUpload Then
Dim fu As FileUpload = b
If fu.HasFile Then
fu.SaveAs(Server.MapPath("../Images/PictureStore/").ToString & fu.FileName)
End If
End If
Next
End If
Next
End If
Next
End Sub
Private Sub BuildFTPTable()
Dim table As New Table
table.ID = "uTable"
Dim ftpSize As Integer = CInt(ConfigurationManager.AppSettings("ftpSize").ToString)
For i As Integer = 1 To ftpSize
table.Rows.Add(New TableRow)
table.Rows(i - 1).Cells.Add(New TableCell)
table.Rows(i - 1).Cells(0).Controls.Add(New FileUpload)
Next
Dim b As New Button
b.Text = "Upload Files"
AddHandler b.Click, AddressOf bUpload_Click
table.Rows.Add(New TableRow)
table.Rows(ftpSize).Cells.Add(New TableCell)
table.Rows(ftpSize).Cells(0).Controls.Add(b)
up.Controls.Add(table)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Me.IsPostBack Then
BuildFTPTable()
End If
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
Dim table As Table = up.FindControl("uTable")
If Not table Is Nothing Then
Response.Write("I am something")
Else
Response.Write("I am nothing")
End If
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="up" runat="server" CssClass="Content" >
<hr />
<h1>Recent Picture Uploads</h1>
<asp:DataList ID="recentpictures" runat="server" RepeatColumns="5" RepeatDirection="Horizontal">
<ItemTemplate>
<center>
<img src='<%# Eval("VirtualServerPath") %>' alt='<%# Eval("filename") %>' /><br />
<asp:Label ID="filename" runat="server" Text='<%# Eval("filename") %>' />
</center>
</ItemTemplate>
</asp:DataList>
<hr />
</asp:Panel>
</asp:Content>
I am guessing there is a command to keep the controls available during the round trip but I do not know what that would be.
Thanks
Cassidy